+ Reply to Thread
Results 1 to 7 of 7

Remove lead single quote keeping lead zero

Hybrid View

  1. #1
    Registered User
    Join Date
    04-02-2014
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    79

    Remove lead single quote keeping lead zero

    Hi All,

    I need a VB code to remove all leading single quotes from all cells in a worksheet.
    The cells may or may not contain quotes. Some of the cells contains alpha numeric,dates,numeric with leading zeros. i want to retain those zeros as well.
    ex: '01234 as 1234
    'qwerty12345 as qwerty12345
    '02/12/2015 as 02/12/2015

    I tried by using excel formula "SUBSTITUTE(cell reference,CHAR(39),"")". its working well but i need to do this for the entire worksheet where ever there is a leading single quote.
    Any help is greatly appreciated.



    Thanks
    Shreeja

  2. #2
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Remove lead single quote keeping lead zero

    Sub ridQuotes()
    For Each abc in Range("A1:zz99999") 'replace with your range
            if((left(abc.value,1) = "'") AND (len(abc.value > 1))then
                   abc.value = right(abc.value,len(abc.value)-1
            End If
    Next abc
    End Sub
    apologies, line 4 should have said:

    abc.Value = Right(abc.Value, Len(abc.Value) - 1)
    Last edited by pjwhitfield; 01-05-2015 at 05:59 AM.
    If someone has helped you then please add to their Reputation

  3. #3
    Registered User
    Join Date
    04-02-2014
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: Remove lead single quote keeping lead zero

    Hi pjwhitfield,

    thanks for the reply.
    the code shows syntax error on line
     abc.value = right(abc.value,len(abc.value)-1
    .

    Thanks
    Shreeja

  4. #4
    Forum Expert sourabhg98's Avatar
    Join Date
    10-22-2014
    Location
    New Delhi, India
    MS-Off Ver
    Excel 2007, 2013
    Posts
    1,899

    Re: Remove lead single quote keeping lead zero

    Hey i dont know much about VBA but try this method--
    1. Create a new sheet
    2. in the developers tab go to insert>>module and paste this code
    3. in the new sheet insert a button and right click >>>assign macro>>test
    now click that button and see if your problem is solved.....


    Sub test()
    Range("A1").Select
    ActiveCell.FormulaR1C1 = "=SUBSTITUTE(Sheet1!RC,""'"","""")"
    'replace sheet1 by your sheet which contains the data

    Range("A1").Select
    Selection.Copy
    Range("A1:P22").Select
    'here change the range to your data range

    ActiveSheet.Paste
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Sheet1").Select
    'replace sheet1 by your sheet which contains the data

    Cells.Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Application.CutCopyMode = False

    End Sub

    Hope it helps....
    Regards

  5. #5
    Registered User
    Join Date
    04-02-2014
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: Remove lead single quote keeping lead zero

    Hi Sourabhg98, it works well.. thanks a lot.. you saved me a lot of time.

    Thanks
    Shreeja.

  6. #6
    Forum Expert sourabhg98's Avatar
    Join Date
    10-22-2014
    Location
    New Delhi, India
    MS-Off Ver
    Excel 2007, 2013
    Posts
    1,899

    Re: Remove lead single quote keeping lead zero

    Glad to know that it worked.....
    Cheers

  7. #7
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Remove lead single quote keeping lead zero

    The problem you have with substitute is if there are any single quotes legitimately within the data then thety will also be removed.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Keeping lead zeros in excel cells
    By shreeja178 in forum Excel General
    Replies: 3
    Last Post: 07-16-2014, 12:00 AM
  2. [SOLVED] lead zero are being dropped
    By pfournier80 in forum Excel General
    Replies: 6
    Last Post: 08-12-2012, 02:45 AM
  3. Lead Organizer
    By Greg_Excel in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-26-2010, 04:51 PM
  4. Lead scruber
    By huskler1244 in forum Excel General
    Replies: 2
    Last Post: 10-21-2008, 01:23 PM
  5. [SOLVED] Keep Lead Zeros
    By Laury in forum Excel General
    Replies: 7
    Last Post: 04-13-2006, 11:36 AM

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1