Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VBA Excel执行while和If条件_Vba - Fatal编程技术网

VBA Excel执行while和If条件

VBA Excel执行while和If条件,vba,Vba,下面的代码有时会起作用,对于两个以上的值,它会显示一个提到溢出的错误。 我只想为列中的值编写一个VBA代码,以分隔三个类别,并计算每个类别中的数字。请告诉我这个代码的错误 Sub income_status() Dim income As Integer Dim locount As Integer Dim mecount As Integer Dim hicount As Integer Do While ActiveCell.Value <> "" income

下面的代码有时会起作用,对于两个以上的值,它会显示一个提到溢出的错误。 我只想为列中的值编写一个VBA代码,以分隔三个类别,并计算每个类别中的数字。请告诉我这个代码的错误

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
Sub-income_status()
作为整数的模糊收入
Dim locount为整数
Dim mecount为整数
Dim hicount为整数
当ActiveCell.Value“”时执行此操作
收入=活动单元格。价值

如果收入10000且收入则整数的最大值为32767。当然还有比这更高的收入,特别是因为你检查的价值高于5万英镑。将所有变量声明为long:

Dim income As Long
Dim locount As Long
Dim mecount As Long
Dim hicount As Long

其余的应该是相同的。

整数的最大值是32767。当然还有比这更高的收入,特别是因为你检查的价值高于5万英镑。将所有变量声明为long:

Dim income As Long
Dim locount As Long
Dim mecount As Long
Dim hicount As Long

其余的都应该是一样的。

你能分享准确的错误吗?你需要将你的变量声明为Long….
Dim income as Long
你需要关注未来,正如@DoronYakovlev Golani提到的,确保包括错误发生的那一行和你收到的准确错误。它使故障排除变得容易得多。欢迎来到StackOverflow!!!你能分享准确的错误吗?你需要将你的变量声明为Long…
Dim income as Long
你需要关注未来,正如@DoronYakovlev Golani提到的,确保包括错误发生的那一行和你收到的准确错误。它使故障排除变得容易得多。欢迎来到StackOverflow!!!“其余的应该是一样的”-是的。好吧,除了垃圾缩进和依赖于
ActiveCell
。选择
;-)@Mat'sMug哈哈哈。非常正确。希望OP能看到问题评论中提供的链接。:)“其余的应该是一样的”-是的。好吧,除了垃圾缩进和依赖于
ActiveCell
。选择
;-)@Mat'sMug哈哈哈。非常正确。希望OP能看到问题评论中提供的链接。:)