Search code examples
vbaexceluserform

Userform in Excel to control the flow of a macro


This has got to be ridiculously easy, but I just cannot figure it out searching the web.

I have an Excel macro that performs various data entry/manipulation tasks. There is a point in the macro where I want the user to have the option of using data in column A or column B for calculations. All I want is to call a userform with two command buttons which pass their "true" or "false" value to the main macro and then perform "if" statements based on this information.

The trouble is I cannot get the userform to "tell" the macro anything. I'm sure this is a major noob question and I'm missing the method, but I cannot get this to work. Thank you!

Edit, I've attached the userform code below by request:

Private Sub CommandButton1_Click()
Unload Me
End Sub

Private Sub OptionButton1_Click()
End Sub

Private Sub OptionButton2_Click()
End Sub

Private Sub UserForm_Initialize()
End Sub

Solution

  • you could avoid userform for that and use a simple message box:

    If MsgBox("use data in column A or B [Yes=A, NO=B]", vbYesNo) = vbYes Then
        ' code for using data in column A
    Else
        ' code for using data in column B
    End If