Results 1 to 6 of 6

Thread: Add +33 to phone number in place of 0

  1. #1
    Join Date
    Aug 2009
    Posts
    57

    Add +33 to phone number in place of 0

    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?

  2. #2
    Join Date
    Nov 2005
    Posts
    1,323

    Re: Add +33 to phone number in place of 0

    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

  3. #3
    Join Date
    Aug 2009
    Posts
    57

    Re: Add +33 to phone number in place of 0

    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.

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Add +33 to phone number in place of 0

    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.

  5. #5
    Join Date
    Nov 2008
    Posts
    1,192

    Re: Add +33 to phone number in place of 0

    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

  6. #6
    Join Date
    Aug 2009
    Posts
    57

    Re: Add +33 to phone number in place of 0

    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

Similar Threads

  1. Replies: 4
    Last Post: 16-01-2012, 04:49 PM
  2. Replies: 6
    Last Post: 25-12-2011, 09:04 PM
  3. How to block a phone number on cell phone
    By Segvoia in forum Off Topic Chat
    Replies: 8
    Last Post: 19-07-2011, 02:14 PM
  4. isp phone number
    By Rooks in forum Windows Software
    Replies: 3
    Last Post: 17-06-2009, 09:24 AM
  5. EA Games phone number?
    By Panther X in forum Video Games
    Replies: 5
    Last Post: 14-11-2008, 03:19 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,728,379.56054 seconds with 16 queries