我是VBA的新手,请帮我解决以下问题。
在面对OVERFLOW
错误时运行
total = 0
employee = InputBox("Enter the employee Name")
For Each sheet In Worksheets
For i = 2 To 13
If sheet.Cells(i, 2).Value = employee Then
total = sheet.Cells(i, 3).Value + total
End If
Next i
Next sheet
答案 0 :(得分:1)
您可能会溢出total
变量,因为它可能默认为存储的INTEGER,最多只能容纳两个字节(-32768到32767)。
而是使用可容纳更多数据的类型声明您的变量:
Dim total as Long
total = 0
employee = InputBox("ENter the employee Name")
For Each sheet In Worksheets
For i = 2 To 13
If sheet.Cells(i, 2).Value = employee Then
total = sheet.Cells(i, 3).Value + total
End If
Next i
Next sheet