C
Cloudfall
I am trying to eliminate the spaces between digits in Australian
Business Numbers which have the format "NN NNN NNN NNN" to produce an
eleven digit number with no spaces. I have written a function to do
this that appears to work. I now want to call this function from a
subroutine to change about 3000 numbers. The subroutine is causing me
headaches. Here is my space-eliminating function:
Function RemoveSpaces(CellContents As String) As String
Do While InStr(1, CellContents, " ") > 0
CellContents = Replace(CellContents, " ", "")
Loop
RemoveSpaces = CellContents
End Function
Here is my subroutine:
Sub abnTidy2()
Dim CellContents As String
Sheets("Scratch").Select
Range("E2").Select 'which contains the number 17 000 032 128
CellContents = Selection.Value
Do While CellContents <> Null
Call RemoveSpaces(CellContents)
Selection.Offset(1, 0).Select
CellContents = Selection.Value
Loop
End Sub
Cell "E2" contains the number "17 000 032 128".
Using the debugger, I step all the way to "Do While CellContents <>
Null", and the next time I "step into" it jumps to "End Sub". Now, my
"Locals" window confirms that ell "E2" contains the string "17 000 032
128", so it isn't null. So, if CellContents is not Null, the debugger
should step to the function call "Call RemoveSpaces(CellContents)". It
doesn't do this and I can't figure out why.
Can anybody help, please? Also, criticisms / comments / style tips
regarding my code would be warmly appreciated.
Business Numbers which have the format "NN NNN NNN NNN" to produce an
eleven digit number with no spaces. I have written a function to do
this that appears to work. I now want to call this function from a
subroutine to change about 3000 numbers. The subroutine is causing me
headaches. Here is my space-eliminating function:
Function RemoveSpaces(CellContents As String) As String
Do While InStr(1, CellContents, " ") > 0
CellContents = Replace(CellContents, " ", "")
Loop
RemoveSpaces = CellContents
End Function
Here is my subroutine:
Sub abnTidy2()
Dim CellContents As String
Sheets("Scratch").Select
Range("E2").Select 'which contains the number 17 000 032 128
CellContents = Selection.Value
Do While CellContents <> Null
Call RemoveSpaces(CellContents)
Selection.Offset(1, 0).Select
CellContents = Selection.Value
Loop
End Sub
Cell "E2" contains the number "17 000 032 128".
Using the debugger, I step all the way to "Do While CellContents <>
Null", and the next time I "step into" it jumps to "End Sub". Now, my
"Locals" window confirms that ell "E2" contains the string "17 000 032
128", so it isn't null. So, if CellContents is not Null, the debugger
should step to the function call "Call RemoveSpaces(CellContents)". It
doesn't do this and I can't figure out why.
Can anybody help, please? Also, criticisms / comments / style tips
regarding my code would be warmly appreciated.