I am trying to run VBA code to add a leading zero so that the figures are 2 in length;
e.g. 1 becomes 01
I have looked around and found some code, it doesn't error but it doesn't add a leading zero when run.
I have attached an example sheet.![]()
Sub Leading_Zero() Dim LZero As String Application.ScreenUpdating = False LZero = Empty Worksheets(1).Columns("A").NumberFormat = "@" Range("A1").Select If Len(Cell) < 2 Then Cell = WorksheetFunction.Rept("0", 1 - Len(Cell)) & Cell End If Do Until LZero = "End" ActiveCell.Offset(7, 0).Activate If ActiveCell.Value <> "" Then If Len(Cell) < 2 Then Cell = WorksheetFunction.Rept("0", 1 - Len(Cell)) & Cell End If ElseIf ActiveCell.Value = "" Then LZero = "End" End If Loop Application.ScreenUpdating = True Range("A1").Select End Sub
Bookmarks