I have been using this code for adding zeroes to IDs for a while now, and it always works without fail. Until today it started saying the code execution has been interrupted.
Sub AddZeroes()
'Declarations
Dim i As Long, j As Long, 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
It always highlights either the
DO WHILE LEN(ACTIVECELL.VALUE) < 7
or it highlights the
LOOP
#N/A!,#DIV/0!and so on