0
我有下面的代碼,突如其來的隨機誤差
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
,並將其添加前面的零爲數字並將它們轉換爲文本,使它們長7個charecters如果他們是小於7,並已工作了一一天,它突然停止了。我不斷收到錯誤RUN TIME ERROR 6 OVERFLOW。我感到茫然,因爲它一直工作到現在一直沒有任何問題。它不斷突出部分:
For i = 1 To endrow - 1
有什麼想法?
你不需要「Do ... Loop」將0加到數字的前面。 'Activecell.value = right(Activecell.value,string $(7,「0」),7)'將在一個語句中這樣做。另外,爲了避免'select'語句,我會改變你的整個循環爲:for i = 2 to endrow-1:cells(i,1)= right(cells(i,1),string $(7,「 0「),7):next' – SeanC