我有以下宏,它将0添加到ID号码中,直到它们是7个数字为止。我以前用过无数次,直到今天它一直运行无误,并且代码For i = 1 To endrow - 1
的部分每次都突出显示,我无法调试问题。整个代码是。Excel VBA代码错误
Sub AddZeroes()
'Declarations
Dim i As Integer, j As Integer, endrow As Long
'Converts the A column format to Text format
Application.ScreenUpdating = False
Columns("A:A").Select
Selection.NumberFormat = "@"
'finds the bottom most row
endrow = ActiveSheet.Range("A1").End(xlDown).Row
'selects the top cell in column A
ActiveSheet.Range("A1").Select
'loop to move from cell to cell
For i = 1 To endrow - 1
'Moves the cell down 1. Assumes there's a header row so really starts at row 2
ActiveCell.Offset(1, 0).Select
'The Do-While loop keeps adding zeroes to the front of the cell value until it hits a length of 7
Do While Len(ActiveCell.Value) < 7
ActiveCell.Value = "0" & ActiveCell.Value
Loop
Next i
Application.ScreenUpdating = True
End Sub
** endrow **在停止点的价值是多少?另外,如果格式仅用于显示目的,那么整个例程可以用'Columns(“A:A”)替换。NumberFormat =“0000000”' – SeanC
Endrow部分是告诉它在最后一行停止,通常它会减少一个额外的行并添加一个只有7个0的单元。 -1告诉它在最后一个单元停止。 – user1958651
当代码被突出显示以指示错误时,** endrow **在该点的值是什么? – SeanC