Eliminate Pivot Table Annoyances
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 10 of 10

Thread: Run module from user form

  1. #1
    New Member
    Join Date
    Jun 2017
    Posts
    10
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Run module from user form

    How do i run a module from a userform. Is there a specific code i use or do i simply write call module1?

  2. #2
    Board Regular Logit's Avatar
    Join Date
    Aug 2016
    Location
    United States
    Posts
    1,347
    Post Thanks / Like
    Mentioned
    12 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Run module from user form

    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.

  3. #3
    New Member
    Join Date
    Jun 2017
    Posts
    10
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Run module from user form

    Thank you..... Would i just write for example
    Sub button
    Call module1
    Endsub?

  4. #4
    Board Regular My Aswer Is This's Avatar
    Join Date
    Jul 2014
    Posts
    12,300
    Post Thanks / Like
    Mentioned
    9 Post(s)
    Tagged
    4 Thread(s)

    Default Re: Run module from user form

    It would look like this:

    Code:
    Private Sub CommandButton1_Click()
    Call Macro1
    End Sub
    Be sure and always test this script on sample data the first time you use this as to avoid any problems with your data. Always trying to learn more and help others where I can. I'm using Excel 2013.
    Patience please Iím not perfect yet. "Memories are forever"

  5. #5
    Board Regular Logit's Avatar
    Join Date
    Aug 2016
    Location
    United States
    Posts
    1,347
    Post Thanks / Like
    Mentioned
    12 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Run module from user form

    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 by Logit; Jun 19th, 2017 at 08:20 PM.

  6. #6
    New Member
    Join Date
    Jun 2017
    Posts
    10
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Run module from user form

    thank you. forgot to post this.... it helped

  7. #7
    Board Regular Logit's Avatar
    Join Date
    Aug 2016
    Location
    United States
    Posts
    1,347
    Post Thanks / Like
    Mentioned
    12 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Run module from user form

    You are welcome

  8. #8
    New Member
    Join Date
    Jun 2017
    Posts
    10
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Run module from user form

    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.

  9. #9
    New Member
    Join Date
    Jun 2017
    Posts
    10
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Run module from user form

    Quote Originally Posted by VBAer View Post
    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

  10. #10
    Board Regular Logit's Avatar
    Join Date
    Aug 2016
    Location
    United States
    Posts
    1,347
    Post Thanks / Like
    Mentioned
    12 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Run module from user form

    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 !

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •