Run module from user form

VBAer

New Member
Joined
Jun 13, 2017
Messages
10
How do i run a module from a userform. Is there a specific code i use or do i simply write call module1?
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Presuming you are using a CommandButton on the UserForm to fire the macro ...

Doubleclick the command button. In the sub that appears, call the macro from there.
 
Upvote 0
It would look like this:

Code:
Private Sub CommandButton1_Click()
Call Macro1
End Sub
 
Upvote 0
Thank you..... Would i just write for example
Sub button
Call module1
Endsub?

Yes ... but don't call your macro "button". Try to avoid using key words that Excel recognizes as standard commands or name of objects.

You could do :
Code:
Sub CommandButton1_Click()
    Call MyMac1

End Sub
 
Last edited:
Upvote 0
could you help me with a new project please

im kinda still new to VBA and need some help with the coding 0

i need to make a combo box that lists all items in column A where the user can add to the list (on excel sheet) and have it auto update. once the user selects an item, i want to have a text box show the data in the cell to the right of the item (cell) selected.

im just really new and not exactly how to set up the range with lastrow and xlup, as well as the offset (1,0) or offset (0,1)

thank you in advance for your help.
 
Upvote 0
could you help me with a new project please

im kinda still new to VBA and need some help with the coding 0

i need to make a combo box that lists all items in column A where the user can add to the list (on excel sheet) and have it auto update. once the user selects an item, i want to have a text box show the data in the cell to the right of the item (cell) selected.

im just really new and not exactly how to set up the range with lastrow and xlup, as well as the offset (1,0) or offset (0,1)

thank you in advance for your help.


actually found the answer to my own question... in case anyone sees this
Private Sub UserForm_Initialize()
Dim i As Long
Dim LastRow As Long
Dim ws As Worksheet
Set ws = Sheets("Sheet1")
LastRow = ws.range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LastRow
Me.ComboBox1.AddItem ws.Cells(i, "A").Value
Next i
End Sub
Private Sub ComboBox1_Change()
Dim i As Long
Dim LastRow As Long
Dim ws As Worksheet
Set ws = Sheets("Sheet1")
LastRow = ws.range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LastRow
If (Me.ComboBox1.Value) = ws.Cells(i, "A") Then
Me.TextBox1 = ws.Cells(i, "B").Value
End If
Next i


End Sub
 
Upvote 0
Good show ! Glad you took the initiative to seek the answer. Everyone here is willing to assist ... and even more ready to assist those who aren't sitting on their hands waiting for a handout.

For future reference, when you need assistance with a different challenge, always post it in a NEW THREAD. The purpose of this is to provide the best result when others use the FORUM SEARCH function looking for an answer.
Having more than one topic in a single thread often negates the search effectiveness.

Cheers !
 
Upvote 0

Forum statistics

Threads
1,213,489
Messages
6,113,953
Members
448,535
Latest member
alrossman

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