+ Reply to Thread
Results 1 to 16 of 16

Simple macro needed to format and update a column of values

  1. #1
    Registered User
    Join Date
    09-09-2011
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010
    Posts
    52

    Simple macro needed to format and update a column of values

    Hi,

    I've never written an Excel macro before, so I'm a little confused as to how I would begin with this.

    The task seems pretty simple. I need to iterate through a column of values.

    For each value:
    * Format as text
    * If the value contains an apostrophe as its first character, remove the apostrophe

    Thank you for your help!
    Last edited by hk106; 02-22-2012 at 02:58 PM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Simple macro request

    Hi,

    Are the values you mention all 'numbers' that appear as text and you want to see real numbers?

    If so just enter the number 1 somewhere. Copy it. Select your column of values and then use Paste Special Multiply.

    Regards
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    09-09-2011
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010
    Posts
    52

    Re: Simple macro request

    Richard,

    Actually, the problem is that the Excel file removes leading zeros, so they are brought in with a preceding apostrophe. Then the format is changed to text before the apostrophe gets stripped away to prevent from losing the leading zeros.

    I could easily resolve this with a formula, but a macro needs to be created because this will be a continuing process and the department that will use the file would benefit from being able to use a macro as opposed to using formulas.

  4. #4
    Registered User
    Join Date
    01-20-2012
    Location
    New Jersey
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: Simple macro needed to format and update a column of values

    Would something like this work?

    Please Login or Register  to view this content.
    Just add a 0 for every number you need. You DONT need to convert to text or include an apostraphe. Assuming you want all your numbers to be the same number of leading (before decimal) digits, this should work.

    You can throw that in a vba macro or just add a custom format that is 5 zeros.

  5. #5
    Registered User
    Join Date
    09-09-2011
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010
    Posts
    52

    Re: Simple macro needed to format and update a column of values

    scantron,

    Actually, I'm working with codes that can have all kinds of values ("2835K8", "000F83", "028374"). I have no way of knowing if zeros will be at the beginning of a code, or how many. I just can't have the leading zeros removed, because they're part of the code.
    Last edited by hk106; 02-23-2012 at 09:15 AM.

  6. #6
    Registered User
    Join Date
    09-09-2011
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010
    Posts
    52

    Re: Simple macro needed to format and update a column of values

    So can anyone help with this?

    Thanks.

  7. #7
    Registered User
    Join Date
    09-09-2011
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010
    Posts
    52

    Re: Simple macro needed to format and update a column of values

    Anyone? Please?

  8. #8
    Registered User
    Join Date
    09-09-2011
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010
    Posts
    52

    Re: Simple macro needed to format and update a column of values

    ***bump***

  9. #9
    Registered User
    Join Date
    09-09-2011
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010
    Posts
    52

    Re: Simple macro needed to format and update a column of values

    ***bump***

  10. #10
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Simple macro needed to format and update a column of values

    Okay, so you want the final value to be text, correct?
    I'm only a beginner with VBA but try this code
    Please Login or Register  to view this content.
    Does that work for you?
    Last edited by ChemistB; 02-23-2012 at 05:40 PM.
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  11. #11
    Registered User
    Join Date
    09-09-2011
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010
    Posts
    52

    Re: Simple macro needed to format and update a column of values

    ChemistB,

    Thanks for the response.

    I think you're probably close. Two things:

    1) I have no way of knowing how many records there will be, so is there a way to iterate through a column until there's no value?
    2) After formatting the value as text, the macro must see if the value has a leading apostrophe. If it does, the apostrophe must be removed.

    Thanks

  12. #12
    Registered User
    Join Date
    09-09-2011
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010
    Posts
    52

    Re: Simple macro needed to format and update a column of values

    ***bump***

  13. #13
    Registered User
    Join Date
    09-09-2011
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010
    Posts
    52

    Re: Simple macro needed to format and update a column of values

    Does anyone know how to create a simple macro on this forum?

  14. #14
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Simple macro needed to format and update a column of values

    Which apostrophe do you mean?.
    All text has an apostrophe by default, (or a " or ^) depending how its formatted. You can't remove those.
    If you mean the character ' then just use

    =IF(LEFT(A1)<>"'",A1,RIGHT(A1,LEN(A1)-1))

    Regards

  15. #15
    Registered User
    Join Date
    09-09-2011
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010
    Posts
    52

    Re: Simple macro needed to format and update a column of values

    Yes, but how would one structure this in a macro that loops through a column with an undetermined number of values?

  16. #16
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Simple macro needed to format and update a column of values

    Personally I'd avoid a looping VBA.
    Always use standard excel functionality in preference and only resort to VBA if necessary and even then only use a loop as a very last resort.

    Just copy that formula down a spare column, then copy it and paste special values back on top of the original.
    If you really must have a macro then perform the same functionality.
    e.g. supposing column D contains the values with leading apostrophes

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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