关于VBA中select循环语句的问题,请高手帮我解答一下。
我在一个用户窗体里的一个复合框里输入以下代码:PrivateSubComboBox2_Change()Dima,cAsIntegerDimbAsObjecta=TextB...
我在一个用户窗体里的一个复合框里输入以下代码:
Private Sub ComboBox2_Change()
Dim a, c As Integer
Dim b As Object
a = TextBox5.Value
b = ComboBox2.Value
Select Case a And b
Case a <= 6 And b = "月"
c = 0.056
ListBox3.Clear
ListBox3.AddItem c
Case a > 6 And a < 12 And b = "月"
c = 0.06
ListBox3.Clear
ListBox3.AddItem c
Case a > 1 And a <= 3 And b = "年"
c = 0.0615
ListBox3.Clear
ListBox3.AddItem c
Case a > 3 And a <= 5 And b = "年"
c = 0.064
ListBox3.Clear
ListBox3.AddItem c
Case a > 5 And b = "年"
c = 0.0655
ListBox3.Clear
ListBox3.AddItem c
End Select
End Sub
但是结果却报错
还请高手指教一下。 展开
Private Sub ComboBox2_Change()
Dim a, c As Integer
Dim b As Object
a = TextBox5.Value
b = ComboBox2.Value
Select Case a And b
Case a <= 6 And b = "月"
c = 0.056
ListBox3.Clear
ListBox3.AddItem c
Case a > 6 And a < 12 And b = "月"
c = 0.06
ListBox3.Clear
ListBox3.AddItem c
Case a > 1 And a <= 3 And b = "年"
c = 0.0615
ListBox3.Clear
ListBox3.AddItem c
Case a > 3 And a <= 5 And b = "年"
c = 0.064
ListBox3.Clear
ListBox3.AddItem c
Case a > 5 And b = "年"
c = 0.0655
ListBox3.Clear
ListBox3.AddItem c
End Select
End Sub
但是结果却报错
还请高手指教一下。 展开
展开全部
首先,你的b设置为对象变量就是个错误
你看下这样可以吗?
Private Sub ComboBox2_Change()
Dim a, c As Integer
Dim b As String
a = TextBox5.Value
b = ComboBox2.Value
If b = "月" Then
If a <= 6 Then
c = 0.056
ElseIf a > 6 And a < 12 Then
c = 0.06
End If
ElseIf b = "年" Then
If a > 1 And a <= 3 Then
c = 0.0615
ElseIf a > 3 And a <= 5 Then
c = 0.064
ElseIf a > 5 Then
c = 0.0655
End If
End If
ListBox3.Clear
ListBox3.AddItem c
End Sub
你看下这样可以吗?
Private Sub ComboBox2_Change()
Dim a, c As Integer
Dim b As String
a = TextBox5.Value
b = ComboBox2.Value
If b = "月" Then
If a <= 6 Then
c = 0.056
ElseIf a > 6 And a < 12 Then
c = 0.06
End If
ElseIf b = "年" Then
If a > 1 And a <= 3 Then
c = 0.0615
ElseIf a > 3 And a <= 5 Then
c = 0.064
ElseIf a > 5 Then
c = 0.0655
End If
End If
ListBox3.Clear
ListBox3.AddItem c
End Sub
更多追问追答
追问
追答
你把那个listbox3改用textbox控件试下,不明白你这什么要用listbox控件。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询