UserForms

mtagliaferri

Board Regular
Joined
Oct 27, 2004
Messages
156
I am new to UserForms and would like to add a kick to some spreadsheets moving some cmd button etc from the actual spreadsheet and and move them to the UserForms and some helps would be great, I have the following UserForm called 'Settings' currently the most impeding issues I have:
  • What code should I be using on a button on the UserForm to run a specific Module/Macro
  • How do you edit a specific Cell on the open protected Worksheet from a text box in the UserForm
Thanks
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
1. Double-click on the button and enter the name of the macro you want to run as a single line in-between the newly inserted Sub.... End Sub bit, similar to this:
Code:
Private Sub Commandbutton1_Click()
    YourMacroNameGoesHere
End Sub

2. Depends on when exactly you want the cell to be updated.
 
Upvote 0
See if you can adapt these:

VBA Code:
Private Sub CommandButton1_Click()

macro1

End Sub

Private Sub CommandButton2_Click()

With Sheets("Sheet1")
    .Unprotect
    .Range("A1").Value = TextBox1.Value
    .Protect
End With

End Sub
 
Upvote 0
Thanks for the prompt reply, I am receiving the error "Compile Error: Expected variable or procedure, not module"
Apologies I should have mentioned I am trying to run a module
 
Upvote 0
You don't run modules, you run the subs/call the functions in them.

Can you post an example of the existing code along with an explanation of how it's currently being executed?
 
Upvote 0
The code is:

VBA Code:
Sub AddYear()
    Dim a As String
    a = Worksheets(Worksheets.Count).Name
    Worksheets(a).Copy After:=Worksheets(a)
    Worksheets(Worksheets.Count).Name = CDbl(a) + 1
End Sub

I am getting confused, If I add a button to the spreadsheet I can assign a Macro and the dialog window 'AddYear' in the list of macros and it works by clicking on the button, I was under the impression would be the same on a UserForm
 
Upvote 0
Its similar. The macro you will be running is a 'button_click' macro. Within that button click macro you call another macro as seen by the first reply. The button click macro is housed in the userform module (right click on the userform in the VBA project explorer and then view code). In your case the macro you will call would normally be in a standard module (eg Module1).
 
Upvote 0
Solution

Forum statistics

Threads
1,213,534
Messages
6,114,186
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top