+ Reply to Thread
Results 1 to 3 of 3

Better way to select data using if and elseif. Case selection

  1. #1
    Registered User
    Join Date
    07-12-2005
    Posts
    21

    Better way to select data using if and elseif. Case selection

    Hi Folks,

    Can anyone help me in finding a better way of writting this code
    if name = "Phil" then goto case1
    elseif name = "Bob" then goto case 2
    elseif name = "Joe" then goto case 1
    elseif name = "Fred" then goto case 3
    elseif name = "Billy" then goto case 1
    elseif name = "Jack" then goto case 3
    elseif name = "Jane" then goto case 2

    There is no logical relation between the name and the case and i have hundreds of these. I was wodereing if you could do something like
    Case1 = "phil", "Joe", "Billy"
    Case2 = "bob","Jane"

    Etc.

    I have tried looking for a soultion but dont really know what to type to get an answer
    Any help would be apprecitaed

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Better way to select data using if and elseif. Case selection

    Yes:

    Please Login or Register  to view this content.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Registered User
    Join Date
    07-12-2005
    Posts
    21

    Re: Better way to select data using if and elseif. Case selection

    Perfect, Thanks Olly. I knew it had to be something like this but couldnt find an answer

+ 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. 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
  2. [SOLVED] Disregard case in VBA code. (UCase, LCase, Select Case)
    By Orestees in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 09-07-2012, 12:12 PM
  3. Case Select compile error "Case without case select"
    By coasterman in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-23-2012, 06:50 AM
  4. Case Select....The alternative method for long "Select Case"
    By kimyap in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-22-2008, 01:24 AM
  5. Fix Code: Select Case and "Contains" selection
    By Bettergains in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-25-2005, 10:06 PM

Tags for this Thread

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