noboffinme
Registered User.
- Local time
- Today, 14:55
- Joined
- Nov 28, 2007
- Messages
- 288
Hi
I'm trying to add a '0' to a phone number field but cannot get my code to work & was wondering why it doesn't.
Here's the code;
------------------------------------------------------------------
Sub add_zero()
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim l As Integer
Dim m As Variant
Dim tmpstring As String
Sheets("DATA").Select
'i is a variable for the 'DATA' worksheets Row number, steps up one by one until it reaches Row 2
For i = Sheets("DATA").Range("H100000").End(xlUp).Row To 2 Step -1
j = 2
k = 8
tmpstring = Cells(i, k).Value
Cells(i, k).Select
'add a leading "0" if there was none
If Mid(tmpstring, 1, 1) <> "0" Then
tmpstring = "0" & tmpstring
tmpstring = Cells(i, k) '.Value
End If
Next i
End Sub
------------------------------------------------------------
The value of 'tmpstring' shows in the locals window as adding the zero the the front of the field value, but it doesn't overwrite the cell with this change.
Can anyone advise why?
Thanks
I'm trying to add a '0' to a phone number field but cannot get my code to work & was wondering why it doesn't.
Here's the code;
------------------------------------------------------------------
Sub add_zero()
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim l As Integer
Dim m As Variant
Dim tmpstring As String
Sheets("DATA").Select
'i is a variable for the 'DATA' worksheets Row number, steps up one by one until it reaches Row 2
For i = Sheets("DATA").Range("H100000").End(xlUp).Row To 2 Step -1
j = 2
k = 8
tmpstring = Cells(i, k).Value
Cells(i, k).Select
'add a leading "0" if there was none
If Mid(tmpstring, 1, 1) <> "0" Then
tmpstring = "0" & tmpstring
tmpstring = Cells(i, k) '.Value
End If
Next i
End Sub
------------------------------------------------------------
The value of 'tmpstring' shows in the locals window as adding the zero the the front of the field value, but it doesn't overwrite the cell with this change.
Can anyone advise why?
Thanks