英文:
I am using add_serial_number VbA code but is getting overflow error
问题
在我的代码下面给出了。
我只有2万行。
我正在使用长数据类型,但不知道为什么会出现运行时错误。
Option Explicit
Sub add_serial_num()
Dim i As Long, lr As Long
lr = Cells(Rows.Count, "B").End(xlUp).Row
For i = 2 To lr
If Cells(i, "B").Value <> "" Then
Cells(i, "A").Value = i - 1
End If
Next i
End Sub
出现溢出运行时错误。
我已经使用了长数据类型。但不知道为什么会出现这个错误。
我只有2万行。
我正在使用长数据类型,但不知道为什么会出现运行时错误。
英文:
Below my code is given.
I have only 20K rows.
I am using long data type but don't know why i am getting run time error.
Option Explicit
Sub add_serial_num()
Dim i As Long, lr As Long
lr = Cells(Rows.Count, "B").End(xlUp).Row
For i = 2 To lr
If Cells(i, "B").Value <> "" Then
Cells(i, "A").Value = i - 1
End If
Next i
End Sub
Getting run time error of overflow.
I have used long data type. But i don't know why i am getting this error.
I have only 20K rows.
I am using long data type but don't know why i am getting run time error.
答案1
得分: 1
这可能发生在列 B 中的某个单元格之一应用了格式,但值与格式不匹配。例如,如果一个单元格格式化为日期,但其值为1,000,000,000。
检查代码停止的行的格式和值。
另一个选项是使用.Value2
而不是.Value
,这将忽略格式。
英文:
This can happen if one of the cells in column B has a format applied to it, but the value doesn't match the format. For example if a cell is formatted as date, but the value is 1,000,000,000.
Check the format and value of whatever row the code stops on.
Another option is to use .Value2
instead of .Value
, this will ignore the formatting.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论