+ Reply to Thread
Results 1 to 8 of 8

If elseif statement

  1. #1
    Registered User
    Join Date
    11-14-2021
    Location
    Tennessee
    MS-Off Ver
    2016
    Posts
    3

    If elseif statement

    Currently I have this code that looks at the data in column D and diplays text in column C based on the text. That works great but how can I use multiple conditions? If column D displays HJBT then display JB HUNT in column C unless column K displays Vancouver WA or Cucamonga then display HUNT RAIL in column C instead of JB Hunt.

    Here's the code:

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by robert22; 11-20-2021 at 02:13 PM.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,849

    Re: If elseif statement

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. As you are new, I have done it for you today.)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: If elseif statement

    Why did not you create a lookup table, then VLOOKUP? Its quite simple and no need to use VBA.
    Quang PT

  4. #4
    Registered User
    Join Date
    11-14-2021
    Location
    Tennessee
    MS-Off Ver
    2016
    Posts
    3

    Re: If elseif statement

    Could you give an example on how to do this?

  5. #5
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,563

    Re: If elseif statement

    Here is an example.
    On the data sheet cells D3:F7 would be the lookup table with the abbreviations in column D, exception locations in column E and output in column F.
    Column C on the Load Sheet is then filled using:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Let us know if you have any questions.
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

  6. #6
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,612

    Re: If elseif statement

    Please Login or Register  to view this content.
    Last edited by protonLeah; 11-18-2021 at 04:53 PM.
    Ben Van Johnson

  7. #7
    Registered User
    Join Date
    11-14-2021
    Location
    Tennessee
    MS-Off Ver
    2016
    Posts
    3

    Re: If elseif statement

    Both examples great! Thanks for you time and effort. Keep up the great work.

  8. #8
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,563

    Re: If elseif statement

    You're Welcome. Thank You for the feedback and for marking the thread as 'Solved'. I hope that you have a blessed day.

+ 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. If ElseIf statement
    By ColemanJames in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 02-16-2018, 10:43 AM
  2. If ElseIf Else Statement not working
    By lazyserv in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-28-2015, 03:38 AM
  3. Adding CountIf Statement within If/ElseIf Statement
    By freybe06 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-17-2014, 05:09 AM
  4. [SOLVED] If...Then...ElseIf statement
    By BrownBoy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-21-2014, 05:19 PM
  5. Code stepping in to elseif statement when elseif is definitely not true
    By DFrank231 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-13-2013, 05:31 PM
  6. [SOLVED] ElseIF Statement Error
    By UsmanBPD in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-27-2012, 09:37 AM
  7. If then elseif statement
    By Mac10 in forum Excel General
    Replies: 3
    Last Post: 10-02-2010, 09:29 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