以下是我尝试在Multipage Userform命令按钮上使用的代码。此按钮应首先检查您是否选择了7个选项按钮中的一个。如果你没有,它应该要求你选择网站"。如果您根据所选的选项执行此操作,则应为大量命名文本框生成默认值。但是,当代码运行时,我收到一个错误,指出Select Case和第一个Case"之间的语句或标签无效。我不熟悉在VBA中使用Case语句,但我认为它可能比嵌套ifs更好。然而,看起来我做错了什么,并希望你们能帮助我弄清楚是什么。
我正在使用Excel 2013,但该文件将在使用Excel 2007的计算机上运行。
Private Sub SiteNext_Click()
If Me.OptionButton1.Value = False And Me.OptionButton2.Value = False And Me.OptionButton3.Value = False And Me.OptionButton4.Value = False And _
Me.OptionButton5.Value = False And Me.OptionButton6.Value = False And Me.OptionButton7.Value = False Then
MsgBox "Select Site"
Exit Sub
Else
Select Case Me.OptionButton1.Value = True
LocalTier1.Value = "600"
LocalTier2.Value = "250"
LocalTier3.Value = "175"
LocalTier4.Value = "125"
LocalTier5.Value = "85"
LocalTier6.Value = "65"
LocalTier7.Value = "40"
LocalTier8.Value = "25"
LocalTier9.Value = "10"
LocalTier10.Value = "5"
LocalTier11.Value = "5"
DriveTier1.Value = "600"
DriveTier2.Value = "250"
DriveTier3.Value = "175"
DriveTier4.Value = "125"
DriveTier5.Value = "85"
DriveTier6.Value = "65"
DriveTier7.Value = "40"
DriveTier8.Value = "25"
DriveTier9.Value = "10"
DriveTier10.Value = "5"
DriveTier11.Value = "5"
OuterTier1.Value = "600"
OuterTier2.Value = "250"
OuterTier3.Value = "200"
OuterTier4.Value = "150"
OuterTier5.Value = "100"
OuterTier6.Value = "75"
OuterTier7.Value = "45"
OuterTier8.Value = "30"
OuterTier9.Value = "15"
OuterTier10.Value = "10"
OuterTier11.Value = "5"
Case Me.OptionButton2.Value = True
LocalTier1.Value = "250"
LocalTier2.Value = "225"
LocalTier3.Value = "150"
LocalTier4.Value = "120"
LocalTier5.Value = "80"
LocalTier6.Value = "50"
LocalTier7.Value = "25"
LocalTier8.Value = "15"
LocalTier9.Value = "10"
LocalTier10.Value = "5"
LocalTier11.Value = "5"
DriveTier1.Value = "300"
DriveTier2.Value = "225"
DriveTier3.Value = "150"
DriveTier4.Value = "120"
DriveTier5.Value = "80"
DriveTier6.Value = "50"
DriveTier7.Value = "25"
DriveTier8.Value = "15"
DriveTier9.Value = "10"
DriveTier10.Value = "5"
DriveTier11.Value = "5"
Case Me.OptionButton3.Value = True
LocalTier1.Value = "200"
LocalTier2.Value = "175"
LocalTier3.Value = "125"
LocalTier4.Value = "75"
LocalTier5.Value = "60"
LocalTier6.Value = "40"
LocalTier7.Value = "20"
LocalTier8.Value = "15"
LocalTier9.Value = "10"
LocalTier10.Value = "5"
LocalTier11.Value = "5"
DriveTier1.Value = "225"
DriveTier2.Value = "200"
DriveTier3.Value = "150"
DriveTier4.Value = "100"
DriveTier5.Value = "80"
DriveTier6.Value = "60"
DriveTier7.Value = "30"
DriveTier8.Value = "20"
DriveTier9.Value = "15"
DriveTier10.Value = "10"
DriveTier11.Value = "10"
Case Me.OptionButton4.Value = True
LocalTier1.Value = "175"
LocalTier2.Value = "150"
LocalTier3.Value = "100"
LocalTier4.Value = "60"
LocalTier5.Value = "45"
LocalTier6.Value = "25"
LocalTier7.Value = "10"
LocalTier8.Value = "5"
LocalTier9.Value = "5"
DriveTier1.Value = "200"
DriveTier2.Value = "175"
DriveTier3.Value = "125"
DriveTier4.Value = "100"
DriveTier5.Value = "50"
DriveTier6.Value = "30"
DriveTier7.Value = "15"
DriveTier8.Value = "10"
DriveTier9.Value = "10"
Case Me.OptionButton5.Value = True
LocalTier1.Value = "175"
LocalTier2.Value = "150"
LocalTier3.Value = "100"
LocalTier4.Value = "60"
LocalTier5.Value = "40"
LocalTier6.Value = "20"
LocalTier7.Value = "15"
LocalTier8.Value = "10"
LocalTier9.Value = "5"
LocalTier10.Value = "5"
DriveTier1.Value = "175"
DriveTier2.Value = "150"
DriveTier3.Value = "100"
DriveTier4.Value = "60"
DriveTier5.Value = "40"
DriveTier6.Value = "20"
DriveTier7.Value = "15"
DriveTier8.Value = "10"
DriveTier9.Value = "5"
DriveTier10.Value = "5"
Case Me.OptionButton6.Value = True
LocalTier1.Value = "75"
LocalTier2.Value = "50"
LocalTier3.Value = "30"
LocalTier4.Value = "20"
LocalTier5.Value = "15"
LocalTier6.Value = "10"
LocalTier7.Value = "5"
DriveTier1.Value = "75"
DriveTier2.Value = "50"
DriveTier3.Value = "30"
DriveTier4.Value = "20"
DriveTier5.Value = "15"
DriveTier6.Value = "10"
DriveTier7.Value = "5"
Case Me.OptionButton7.Value = True
LocalTier1.Value = "50"
LocalTier2.Value = "25"
LocalTier3.Value = "20"
LocalTier4.Value = "10"
LocalTier5.Value = "5"
LocalTier6.Value = "5"
DriveTier1.Value = "50"
DriveTier2.Value = "25"
DriveTier3.Value = "20"
DriveTier4.Value = "10"
DriveTier5.Value = "5"
DriveTier6.Value = "5"
End Select
Me.MultiPage1.Value = 1
End If
End Sub
答案 0 :(得分:1)
您可以使用通用Select Case True
。它将评估每个案例,并在第一个真实案例中执行操作:
Select Case True
Case Me.OptionButton1.Value = True
' actions ...
Case Me.OptionButton2.Value = True
' actions ...
End Select