The underscore is called a "line-continuation" character.
Used to break long lines into multiples.
Note there is a <space> before the underscore.
Set thisrng = Application.InputBox(prompt:= _
"Select the range of cells.", Type:=8)
From Help on Application.InputBox
Type Optional Variant. Specifies the return data type. If this argument is
omitted, the dialog box returns text. Can be one or a sum of the following
values.
Value Meaning
0 A formula
1 A number
2 Text (a string)
4 A logical value (True or False)
8 A cell reference, as a Range object
16 An error value, such as #N/A
64 An array of values
You can use the sum of the allowable values for Type. For example, for an input
box that can accept both text and numbers, set Type to 1 + 2.
Try this amended macro which re-formats the numbers to text before looking at
the Len
Sub Addzeros()
Set thisrng = Application.InputBox(prompt:= _
"Select the range of cells.", Type:=8)
thisrng.NumberFormat = "@"
For Each cell In thisrng
If Len(cell.Value) = 3 Then cell.Value = "0000000" & cell.Value
If Len(cell.Value) = 4 Then cell.Value = "000000" & cell.Value
If Len(cell.Value) = 5 Then cell.Value = "00000" & cell.Value
If Len(cell.Value) = 6 Then cell.Value = "0000" & cell.Value
If Len(cell.Value) = 7 Then cell.Value = "000" & cell.Value
If Len(cell.Value) = 8 Then cell.Value = "00" & cell.Value
If Len(cell.Value) = 9 Then cell.Value = "0" & cell.Value
Next
End Sub
Gord