简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM