我正在嘗試下面的代碼,它反覆拋出'如果沒有如果'和類似的錯誤。我只是不知道錯誤在哪裏,因爲每個if都被正確終止。VBA投擲「其他沒有,如果」錯誤
下面是代碼:
Sub hra_macro()
Dim city As Boolean
Dim salary As Integer
Dim varHRA As Integer
Dim mimHRA As Integer
Dim maxHRA As Integer
Dim A As Integer
Dim B As Integer
Dim Rent As Integer
city = Range("b1").Value
salary = Range("b2").Value
Rent = Range("b3").Value
If city = True Then
varHRA = 0
A = Rent - (salary/10)
B = salary * 0.5
Do While varHRA < salary
varHRA = varHRA + 1
If (varHRA < A And varHRA < B) Then
minHRA = varHRA
End If
If (A < varHRA And A < B) Then
minHRA = A
End If
If (B < varHRA And B < A) Then
minHRA = B
End If
If minHRA > maxHRA Then
maxHRA = minHRA
End If
Exit Do
Else '<<<<<<<<<<<<<<<<<<<< PROBLEM AREA
varHRA = 0
A = Rent - (salary/10)
B = salary * 0.4
Do While varHRA < salary
varHRA = varHRA + 1
If (varHRA < A And varHRA < B) Then
minHRA = varHRA
End If
If (A < varHRA And A < B) Then
minHRA = A
End If
If (B < varHRA And B < A) Then
minHRA = B
End If
If minHRA > maxHRA Then
maxHRA = minHRA
End If
Exit Do
End If
Range("b4").Value = maxHRA
End Sub
請格式化您的代碼,方法是突出顯示它並單擊「{}」按鈕。這次我爲你做了。 – Fionnuala
謝謝。這是我第一次使用該網站。請記住它。 –