下面的代码有时它工作,为两个以上的值,它说的错误提一个溢出。 我只想写一个值的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