下面的代碼有時它工作,爲兩個以上的值,它說的錯誤提一個溢出。 我只想寫一個值的VBA代碼的列在每個類別分開三類和計數數字。請告訴我這段代碼的錯誤。VBA的Excel做,當且如果條件
Sub income_status()
Dim income As Integer
Dim locount As Integer
Dim mecount As Integer
Dim hicount As Integer
Do While ActiveCell.Value <> ""
income = ActiveCell.Value
If income <= 10000 Then
ActiveCell.Offset(0, 1).Value = "Low Income"
locount = locount + 1
ElseIf income > 10000 And income <= 50000 Then
ActiveCell.Offset(0, 1).Value = "Medium Income"
mecount = mecount + 1
Else
ActiveCell.Offset(0, 1).Value = "High Income"
hicount = hicount + 1
End If
ActiveCell.Offset(1).Select
Loop
ActiveCell.Offset(1, 2).Value = locount
ActiveCell.Offset(1, 2).Value = mecount
ActiveCell.Offset(1, 2).Value = hicount
End Sub
你能分享確切的錯誤? –
你需要聲明你的變量爲多長時間......'Dim income As Long' – OpiesDad
你需要觀看[Excel VBA介紹第5部分 - 選擇單元格(範圍,單元格,活動單元格,結束,偏移)](https:// www.youtube.com/watch?v=c8reU-H1PKQ&index=5&t=3043s&list=PLNIs-AWhQzckr8Dgmgb3akx_gFMnpxTN5) – 2016-12-01 18:33:10