Everything is in the title:
I have phone numbers like 0122334455 in a column of my table, they are around 300. I would like to have +33122334455 instead. How can I do that? How can I add +33 (for example) in my phone number?
Everything is in the title:
I have phone numbers like 0122334455 in a column of my table, they are around 300. I would like to have +33122334455 instead. How can I do that? How can I add +33 (for example) in my phone number?
You make a macro:
1) Browse the cells
2) If the first character of the cell is 0 then you replace 33
3) You continue your loop to end.
4) Enjoy
I try to do one with a for loop but I do not know how to acquire the cell, and then perform truncation and concatenation.
You can do that by using functions Substitute and Left. You will have the wizard that will give you full information. Select a cell or the conversion will be effective, then insert menu/function/Text Substitute etc.
If you want the same thing via VBA then:
Code:Option Explicit Sub Tst() Dim LastRow As Long, i As Long, sTmp As String LastRow = Sheet1.Range("A" & Sheet1.Rows.Count).End(xlUp).Row For i = 1 To LastRow sTmp = Sheet1.Range("A" & i) If Left$(sTmp, 1) = 0 Then sTmp = "33" & Right$(sTmp, Len(sTmp) - 1) With Sheet1 .Range("A" & i) = sTmp .Range("A" & i).NumberFormat = "+00000" End With End If Next i End Sub
As my numbers are in column C. I have a C instead of A, and I tried to run the macro but it tells me a bug on this line:
If Left$(sTmp, 1) = 0 Then
It says this type mismatch and because it found an empty cell.
How can I adapt?
The below macro does not work either:
Code:Sub Tst() Dim LastRow As Long, i As Long, sTmp As String LastRow = Sheet1.Range("C" & Sheet1.Rows.Count).End(xlUp).Row For i = 1 To LastRow sTmp = Sheet1.Range("C" & i) If Len(sTmp) > 0 Then With Sheet1 .Range("C" & i) = sTmp .Range("C" & i).NumberFormat = "+00000" End With End If Next i End Sub
Bookmarks