+ Reply to Thread
Results 1 to 4 of 4

Macro to identify column by header and replace number values with string values

  1. #1
    Registered User
    Join Date
    10-22-2013
    Location
    Brooklyn, NY
    MS-Off Ver
    Excel 2003
    Posts
    5

    Macro to identify column by header and replace number values with string values

    Hi, I am stuck on a seemingly simple issue within a much larger Excel macro. I need the macro to find the column headed "PRIORITY" (changes with each data download) and recode number values in the column with their corresponding string values. Currently, the column contains 1's, 2's, and 3's. I need to replace those values with high, medium, and low:

    1=high
    2=medium
    3=low

    The code below is what I have so far. but it theoretically would only work for the first recoding, 1=high. Moreover, even that doesn't work because Excel sees the "PRIORITY" column as containing number values, not string values (the Macro leaves the cell blank instead of filling it with "high").

    Please Login or Register  to view this content.
    Can anyone help with this? Thank you.

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro to identify column by header and replace number values with string values

    Hi kank6789

    You'll need to change this line of Code from
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    To solve this
    it theoretically would only work for the first recoding, 1=high
    I'd suggest a Select Case Statement.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,417

    Re: Macro to identify column by header and replace number values with string values

    You are changing 1 to High ... notice, no quotation marks. Therefore, High is seen as a (undefined) variable and hence has no value. Change it to "High"

    Once you know what the range is, why don't you do a global replace instead of looping through the range?

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Macro to identify column by header and replace number values with string values

    Try:
    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)

Similar Threads

  1. Replies: 0
    Last Post: 10-15-2013, 07:59 PM
  2. Macro to find all specific values in column and replace adjacent cell values
    By dblock02 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-23-2013, 06:03 AM
  3. Replace various number values in cells with a text string
    By tommygray in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-13-2013, 05:35 AM
  4. Macro to select the column values without using header
    By shanmp77 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-30-2010, 06:40 AM
  5. Replies: 0
    Last Post: 10-13-2005, 02:05 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