我真的是VBA的新手,所以我的描述可能不太准确。我正在尝试编写代码以将问卷调查表转换成答案。
我想根据被调查者的回答返回一组可选的答案。 因此,我尝试使用“ selectcase”,但结果发现代码中存在运行时错误“ 9”。
Sub macro111()
'
Dim a As Integer
Dim b As Integer
Dim x As Integer
Dim result As String
For x = 2 To 110
a = Cells(x, 10).Value
Select Case a
Case Is = 1
b = Cells(x, 11).Value
If b = 1 Then
result = "15,001~20,000"
ElseIf b = 2 Then
result = "20,001~30,000"
ElseIf b = 3 Then
result = "30,001~40,000"
ElseIf b = 4 Then
result = "40,001~50,000"
ElseIf b = 5 Then
result = "50,000+"
Cells(x, 43).Value = result
End If
Case Is = 2
macro1
End Select
Next x
End Sub
Sub macro1()
'
s =[{14750,14000;13150,12700;12500,12200;11800,11500;11300,11050;10800,10650;10550,10400;10200,10050}]
arr = [a1].CurrentRegion
For i = 2 To UBound(arr)
For ii = 19 To UBound(arr, 26)
If Len(arr(i, ii)) Then arr(i, ii) = IIf(arr(i, ii) = 1, s(ii - 1, 1), s(ii - 1, 2))
Next
Next
[a1].CurrentRegion = arr
End Sub
它停在
For ii = 19 To UBound(arr, 26)
给出错误“运行时错误9,下标超出范围” 而且我不明白原因。请帮我解决这个问题!
谢谢!