+ Reply to Thread
Results 1 to 4 of 4

macro to compare value against multiple ranges and enter value based on that

  1. #1
    Registered User
    Join Date
    12-31-2013
    Location
    Latrobe Pennsylvania, US
    MS-Off Ver
    Excel 2003
    Posts
    12

    macro to compare value against multiple ranges and enter value based on that

    Hello, I'm just starting to learn VB and have a relatively easy thing I'm trying to do (I believe)

    I want the macro to simply look at a value in a cell (lets say F3), see if it is within a specific range range, and dependent upon which range it falls into, insert a different value for me in another cell. I'm assuming it's gonna be something like IF 1 < F3 < 2 Then F4 = "B"

    i have about 26 ranges that I want it to compare the given value in F3 against, and depending on which range it lies in it would spit back different text but in the same cell every time.

    Thanks for any help!

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: macro to compare value against multiple ranges and enter value based on that

    You would construct a two-column Lookup table. The first column is the beginning of the range wherein you'd want one result, and the second column is the result you'd want. The next row shows the beginning of the next tier and next result, and so on. For example, in columns M:N you might construct this table:

    Please Login or Register  to view this content.
    Then perhaps in F3 you had entered the number 2.5 and wanted the code "C" to appear in F4, the lookup formula would be:

    =VLOOKUP(F3, M:N, 2, 1)


    The answer is "C" because 2.5 falls in the "2" tier, before the start of the "4" tier.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    12-31-2013
    Location
    Latrobe Pennsylvania, US
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: macro to compare value against multiple ranges and enter value based on that

    That worked great, thanks!!

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: macro to compare value against multiple ranges and enter value based on that

    I've marked this thread as SOLVED for you.
    Next time, select Thread Tools from the links above to mark a thread as SOLVED. Thanks.

+ 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. Macro to compare columns and insert codes, according ranges
    By marina_lk in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-16-2013, 03:06 PM
  2. [SOLVED] macro compare 2 ranges but insert row in one range..
    By feroguz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-27-2012, 02:19 PM
  3. Macro to compare multiple columns between 2 spreadsheets based on a single reference
    By chandra79 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-24-2012, 11:13 AM
  4. Macro to compare two ranges in a worksheet.
    By abhay_547 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-06-2010, 11:08 PM
  5. Macro to input and compare date ranges
    By vlad in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-25-2005, 05: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