+ Reply to Thread
Results 1 to 11 of 11

Multiple If Statements

  1. #1
    Registered User
    Join Date
    06-25-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 2003
    Posts
    24

    Multiple If Statements

    Not sure if this would be a macro or not...

    I would like to implement multiple if statements. For example:

    If Cell A1 = "this" then B1 = "that"

    or

    If Cell A1 = "this1" then B1 = "that1"

    or

    If Cell A1 = "this2" then B1 = "that2"

    or

    If FALSE then B1 = ""



    I have about 80 statements I would like to work into a macro, but just need guidance on the basic structure of the macro.

    Thanks so much for any input.

  2. #2
    Registered User
    Join Date
    08-15-2012
    Location
    Las Vegas
    MS-Off Ver
    Excel 2010
    Posts
    87

    Re: Multiple If Statements

    Without fully understanding what you are tyring to accomplish I would think at first glance that a macro solution using "Select Case" would be cleaner.

    Example:

    Please Login or Register  to view this content.
    Hope this gets you started in the right direction.
    Last edited by g8r777; 10-11-2012 at 07:20 PM.

  3. #3
    Valued Forum Contributor
    Join Date
    09-10-2012
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2010
    Posts
    929

    Re: Multiple If Statements

    Why not just use a VLOOKUP?

  4. #4
    Registered User
    Join Date
    06-25-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: Multiple If Statements

    @ djapigo

    I am not familiar with that. Could you elaborate?



    @ g8r777

    Your code works very well here. I've modified it to show you where I am working.

    The goal from here is to extend this all the way down. It creates a value from the data in cell H2 and I need to go down the entire column.



    Please Login or Register  to view this content.

    Thanks for both replies.

    Have a great day,
    Mike.

  5. #5
    Valued Forum Contributor
    Join Date
    09-10-2012
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2010
    Posts
    929

    Re: Multiple If Statements

    Mike,

    VLOOKUPs do not need macros... it's a simple formula with little setup (table range)... you should look up the VLOOKUP formula...

    Here's an example... vlookup sample.xls

    This will be much easier to monitor and change. Then again, I'm not sure what you are trying to do.

    Let me know if you still have any questions.

    Thanks,
    Dennis

  6. #6
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Multiple If Statements

    wont a formula suffice?
    =IF(A1="this","that",IF(A1="this1","that1",IF(A1="this2","that2","")))
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  7. #7
    Valued Forum Contributor
    Join Date
    09-10-2012
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2010
    Posts
    929

    Re: Multiple If Statements

    Martin,

    80 nested ifs might be too much

  8. #8
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Multiple If Statements

    missed the 80 bit! but a vlookup or index/match would be pretty straight forward

  9. #9
    Registered User
    Join Date
    08-15-2012
    Location
    Las Vegas
    MS-Off Ver
    Excel 2010
    Posts
    87

    Re: Multiple If Statements

    I agree that a VLOOKUP will probably work in this case and be easier than coding.

    I originally thought he was going for something that would have another embedded case.

    Something like

    Please Login or Register  to view this content.
    In this case I didn't think VLOOKUP would have worked as well. I also thought he had more code to run depending on the various cases.
    Last edited by g8r777; 10-11-2012 at 08:21 PM.

  10. #10
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,724

    Re: Multiple If Statements

    Depending on what "this" and "that" actually are, it might be possible to calculate them (if they are numbers).

    Pete

  11. #11
    Registered User
    Join Date
    06-25-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: Multiple If Statements

    @Dennis

    That worked very well. I never knew such a formula even existed. I just applied it to over 4000 rows, with a range of about 85 categories. You have saved me much time, definitely easier to work with than a macro.



    @ Everyone Else,

    Thanks for your input as well. That macro works very well, but no doubt this VLOOKUP is much easier.

    This and That were 80 or so different product categories. No numbers here.

    Basically it was if it is this product type, assign it that product category.



    Thanks again everyone!

    Have a great day,

    MIke.

+ 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