Code :
Option Explicit
Sub LeadingZeros()
Dim cel As Range
Dim rg As Range
Dim mx As Integer: mx = 0
Dim cl As Variant
For Each cl In Selection
If Len(cl) > mx Then mx = Len(cl)
Next
rg.NumberFormat = "0" 'this is showing error
Dim i As Integer
For i = 0 To mx - 2
If mx = 1 Then Exit Sub
rg.NumberFormat = rg.NumberFormat & "0"
Next
End Sub
This is a code for filling up the values in cells with leading zeros. It worked just once, but after that not working. I didn't change the code.
Error :