macro wait for command button

ThomasOES

Board Regular
Joined
Aug 29, 2017
Messages
174
Hello

I have an issue with a macro running till the end instead of waiting for a called userform input. Below is the the code and the called userform code. As you see the SamOpt2x macro finds a cell containing "Sample #1 " and selects the cell. At that point the userform macro is called and will use the activecell value to produce a userform label. The label would be "Sample #1 Info". The userform also contains textboxes for the sample info. The userform has a command button that when clicked puts the information in desired cells. Trouble is, the macro runs all the way through and the userform label is "Sample #2 Info". Is there a way to prompt the macro to wait for the SamInf userform command button click?

Code:
Sub Click_SamOpt2x()
Columns("B:B").Find("Sample #1").Select
Call Show_SamInf
Columns("B:B").Find("Sample #2").Select
Call Show_SamInf
End Sub

Code:
Sub Show_SamInf()
SamInf.Show
With SamInf
    .Height = 210
    .Width = 420
    .Caption = "Show_SamInf"
    With SamInf.SamInfLabel
        .Top = 10
        .Width = 400
        .Height = 30
        .Font.Size = 20
        .Caption = ActiveCell.Value & " Info"
        .Font.Bold = True
        .ForeColor = vbBlue
        .TextAlign = fmTextAlignCenter
        .Left = (SamInf.InsideWidth - .Width) / 2
    End With
End Sub
 
Last edited:

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
I found a way

Code:
Sub Show_SamInf()
SamInf.Show Modal
With SamInf
    .Height = 210
    .Width = 420
    .Caption = "Show_SamInf"
    With SamInf.SamInfLabel
        .Top = 10
        .Width = 400
        .Height = 30
        .Font.Size = 20
        .Caption = ActiveCell.Value & " Info"
        .Font.Bold = True
        .ForeColor = vbBlue
        .TextAlign = fmTextAlignCenter
        .Left = (SamInf.InsideWidth - .Width) / 2
    End With
    With SamInf.SamInf_But
        .Top = 120
        .Caption = "OK"
        .Font.Size = 16
        .Font.Bold = True
        .AutoSize = True
        .Left = (SamInf.InsideWidth - .Width) / 2
    End With
End With
Do While SamInf.Visible
DoEvents
Loop
End Sub

Loop while the form is visible. Command button hides form and loop ends.
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,179
Members
452,615
Latest member
bogeys2birdies

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