+ Reply to Thread
Results 1 to 8 of 8

Macro help to trim field

  1. #1
    Registered User
    Join Date
    06-20-2006
    Location
    Detroit area, Michigan
    MS-Off Ver
    Microsoft Office 365 v16
    Posts
    68

    Macro help to trim field

    I have a column that I am looking to create a macro for to trim the leading zeros on all cells that have a value in them.

    The first cell is J2 (J1 is header text) and I need it to trim all cells in the column beginning with J2 and including all rows that have a value.

    The cells have values like:
    00145723
    00451283
    00051876

    I need it to trim the leading zeros.

    I appreciate any help.

    Thanks!

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Macro help to trim field

    VBA?

    1) Select Col.J
    2) go to [Data] -[Text To Columns] - hit [OK]

    HTH

  3. #3
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,448

    Re: Macro help to trim field

    @timmersuds
    Administrative note
    Please update your profile as necessary to properly reflect the exact version(s) of Excel your question relates to. Members tailor answers based on your Excel version. Your profile does not indicate your version.
    Thanks

  4. #4
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,448

    Re: Macro help to trim field

    @timmersuds

    Administrative Note:

    Hi and welcome
    although we value privacy as much as anyone else, it could be important that members have a rough idea of your location. You might in the future post questions which are bound to your regional settings.
    So, please update your profile to something more precise then "Earth" ( country will suffice, no need to be more precise).
    Thank you for helping us to help you

  5. #5
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,416

    Re: Macro help to trim field

    Quote Originally Posted by jindon View Post
    1) Select Col.J
    2) go to [Data] -[Text To Columns] - hit [OK]
    One caution with jindon's suggestion... if your header text contains spaces, commas or semi-colons in it, then select Delimited and click Next when the Text To Columns dialog appears instead of clicking Finish (jindon accidentally called the button's caption as OK)... then when the next dialog page the appears, uncheck any of the characters that are in your header text... then click the Finish button. The reason for this caution is because the Text To Columns dialog box "remembers" its setting from call to call whether set manually in the dialog box or set via a previous call from VBA code so you can never be sure what the settings are when you go to use it.
    Last edited by Rick Rothstein; 11-18-2019 at 12:40 PM.

  6. #6
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Macro help to trim field

    one vba way
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    06-20-2006
    Location
    Detroit area, Michigan
    MS-Off Ver
    Microsoft Office 365 v16
    Posts
    68

    Re: Macro help to trim field

    Thanks for the help - both suggestions work great!

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Macro help to trim field

    You are welcome and thanks for the rep.

+ 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. Trim a field
    By manceI in forum Excel General
    Replies: 1
    Last Post: 10-05-2017, 08:38 AM
  2. [SOLVED] trim to match two sets of input-trim spaces around a character
    By nigelog in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-21-2017, 12:33 PM
  3. VLOOKUP + TRIM, TRIM Lookup table array...
    By mangesh.mehendale in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 10-19-2016, 02:10 AM
  4. Replies: 2
    Last Post: 03-18-2014, 03:58 PM
  5. Trim Macro
    By Phouthavongc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-30-2014, 10:23 AM
  6. How to do a Macro to Trim SSN
    By davant95 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-25-2009, 01:09 AM
  7. Trying to trim a trailing space char and the Trim function isn't working
    By Psychochook in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-30-2007, 11:28 PM

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