简体   繁体   English

Excel中的用户窗体,用于控制宏的流程

[英]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. 我有一个Excel宏,可以执行各种数据输入/操作任务。 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. 宏中有一个要点,我希望用户可以选择使用A列或B列中的数据进行计算。 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. 我只想用两个命令按钮调用一个用户窗体,这两个命令按钮将其“ true”或“ false”值传递给主宏,然后根据此信息执行“ if”语句。

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: 您可以避免使用userform并使用一个简单的消息框:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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