+ Reply to Thread
Results 1 to 12 of 12

Remove last 2 characters of column A

  1. #1
    Registered User
    Join Date
    05-30-2016
    Location
    The Netherlands
    MS-Off Ver
    2013
    Posts
    26

    Smile Remove last 2 characters of column A

    Hello,

    I want to make a macro that removes the last 2 characters of every cell in column A. The amount of rows in column A will vary with each workbook. So it needs to select the entire column A.
    It's for the first sheet in the workbook.
    I'am not experienced with VBA at all, so all the help will be greatly appreciated.

    -Gunther

  2. #2
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Remove last 2 characters of column A

    This should work, assuming all cells have more than 2 characters in column A and assuming you have a column header in A1.

    Please Login or Register  to view this content.
    Last edited by mikeTRON; 08-02-2016 at 05:39 PM.
    Please ensure you mark your thread as Solved once it is. Click here to see how.
    If a post helps, please don't forget to add to our reputation by clicking the star icon in the bottom left-hand corner of a post.

  3. #3
    Registered User
    Join Date
    05-30-2016
    Location
    The Netherlands
    MS-Off Ver
    2013
    Posts
    26

    Re: Remove last 2 characters of column A

    Quote Originally Posted by mikeTRON View Post
    This should work, assuming all cells have more than 2 characters in column A and assuming you have a column header in A1.

    Please Login or Register  to view this content.
    Just tried it and it works perfect, thanks a lot for taking the time and the fast response!

  4. #4
    Registered User
    Join Date
    06-29-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Remove last 2 characters of column A

    Since I've finished before realizing that there is a replay already and my macro is slightly different I'll let myself post it

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-30-2016
    Location
    The Netherlands
    MS-Off Ver
    2013
    Posts
    26

    Re: Remove last 2 characters of column A

    Looks good, i' ll try them both. Thanks!

  6. #6
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Remove last 2 characters of column A

    Bartos works assuming you want to start with row 1, where I assumed you had a header in row 1 but he does bring up a good point about making sure the cell is not less than 2 characters. I added a simple IF statement to just skip the cell if the cell has less than two characters.

    Please Login or Register  to view this content.
    Last edited by mikeTRON; 08-02-2016 at 05:43 PM.

  7. #7
    Registered User
    Join Date
    06-29-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Remove last 2 characters of column A

    mikeTRON
    Absolutely true. Gunther09 didn't specify how does his dataset looks like so we work with what we have.
    But more importantly, if Gunther09 has lots of cells ( > 10'000 ) then it will take LOTS of time. For one off, it might be OK.
    If however he has > 100'000 cells or wants to do it many times than I'd load it to an array and work from there. It will be many many times faster.

  8. #8
    Registered User
    Join Date
    05-30-2016
    Location
    The Netherlands
    MS-Off Ver
    2013
    Posts
    26

    Re: Remove last 2 characters of column A

    Sorry for the lack of information.
    Yes i' am using a header so the first macro works good. The data is usually 8 characters.
    The column contains at max 500 to 600 cells.

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

    Re: Remove last 2 characters of column A

    Quote Originally Posted by Gunther09 View Post
    Sorry for the lack of information.
    Yes i' am using a header so the first macro works good. The data is usually 8 characters.
    The column contains at max 500 to 600 cells.
    Try this
    Please Login or Register  to view this content.

  10. #10
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Remove last 2 characters of column A

    Quote Originally Posted by Bartos View Post
    mikeTRON
    Absolutely true. Gunther09 didn't specify how does his dataset looks like so we work with what we have.
    But more importantly, if Gunther09 has lots of cells ( > 10'000 ) then it will take LOTS of time. For one off, it might be OK.
    If however he has > 100'000 cells or wants to do it many times than I'd load it to an array and work from there. It will be many many times faster.
    Yep, I was mentioning the header row to Gunther more than you.
    How would you do it in an array?

  11. #11
    Registered User
    Join Date
    05-30-2016
    Location
    The Netherlands
    MS-Off Ver
    2013
    Posts
    26

    Re: Remove last 2 characters of column A

    Quote Originally Posted by jindon View Post
    Try this
    Please Login or Register  to view this content.
    This works also.
    Not sure which one to use now

  12. #12
    Registered User
    Join Date
    06-29-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Remove last 2 characters of column A

    jindon
    Very nice one-liner

    mikeTRON
    code as follows,
    it process 1 mln pos in 3.1 sec on notebook with intel i7. My guess is that reading cell by cell would take couple hours.

    Please Login or Register  to view this content.
    Last edited by Bartos; 08-03-2016 at 04:06 AM.

+ 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. Remove special characters from a column
    By protcg in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-02-2015, 03:28 PM
  2. Remove All Characters except numbers from one column only.
    By tdal in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-30-2015, 01:39 AM
  3. [SOLVED] Macro to remove multiple characters in column?
    By emil9216 in forum Excel General
    Replies: 3
    Last Post: 07-31-2012, 09:29 AM
  4. Remove Last 2 Characters in a Column of Data
    By helpjw in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-02-2011, 04:52 PM
  5. Replies: 5
    Last Post: 08-21-2011, 09:10 AM
  6. Copy column but remove last few characters
    By shmee150 in forum Excel General
    Replies: 3
    Last Post: 03-04-2009, 09:06 AM
  7. Remove 1st 3 characters in each field of Excel column
    By Chuck in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-01-2005, 06:06 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