+ Reply to Thread
Results 1 to 10 of 10

How du Case x twice? (Select Case)

  1. #1
    Registered User
    Join Date
    06-18-2012
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    28

    How du Case x twice? (Select Case)

    Hi,

    i wonder how I can case for ex. x twice? Right not I have the script:

    Please Login or Register  to view this content.
    For example I want to:
    Please Login or Register  to view this content.
    Thnx in advance!

  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: How du Case x twice? (Select Case)

    NameX cannot really have two different values in it unless you declare the function as an array and fill/Redim the array as you add each element into the array. If you haven't worked out dealing with arrays, it's major step up in coding.

    Perhaps this a red herring. What's this function really for? You may need to revamp this whole process you're developing to keep it simple.
    _________________
    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
    06-18-2012
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: How du Case x twice? (Select Case)

    Hmm.. I have working with arrays (little bit) but I thought I could solve it much more simple. In C# you can use Break statement to solve it. Dunno how to do it in VBA. Can you give me an example on an nice array to use in this case?

    Bts, hos does your Commercial Services work? What kind of support will I get if I pay for the CS? Everything need to be posted in the Forum or is it PMs?

    Thnx!

    Quote Originally Posted by JBeaucaire View Post
    NameX cannot really have two different values in it unless you declare the function as an array and fill/Redim the array as you add each element into the array. If you haven't worked out dealing with arrays, it's major step up in coding.

    Perhaps this a red herring. What's this function really for? You may need to revamp this whole process you're developing to keep it simple.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How du Case x twice? (Select Case)

    What is the purpose of the function?

    Do you want to return 2 values based on the argument Ex passed to the function?

    PS I don't see how Break would solve this, all it does is terminate a loop or switch.
    If posting code please use code tags, see here.

  5. #5
    Registered User
    Join Date
    06-18-2012
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: How du Case x twice? (Select Case)

    Hi

    Sorry I meant Switch!
    I want to return two values based on one of the case - in this ex. Case A return both Albert and Avery

    Thnx!!

    Quote Originally Posted by Norie View Post
    What is the purpose of the function?

    Do you want to return 2 values based on the argument Ex passed to the function?

    PS I don't see how Break would solve this, all it does is terminate a loop or switch.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How du Case x twice? (Select Case)

    You could do it like this, which will return an array with the 2 names based on Ex.
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    06-18-2012
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: How du Case x twice? (Select Case)

    Thank you so, so, SO much!!!!!!!!!! Will try it !

    Quote Originally Posted by Norie View Post
    You could do it like this, which will return an array with the 2 names based on Ex.
    Please Login or Register  to view this content.

  8. #8
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: How du Case x twice? (Select Case)

    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

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

    Re: How du Case x twice? (Select Case)

    Get your feet wet here, then:
    http://www.cpearson.com/excel/return...ysfromvba.aspx

    I think the last macro example on that page may be the way you address two different values from the functions array results.

  10. #10
    Registered User
    Join Date
    06-18-2012
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: How du Case x twice? (Select Case)

    Hi again!

    I tried you ex but didn't work - It only writes Albert and not Avery. Something spec. I need to think at?

    Thnx!

    Quote Originally Posted by Norie View Post
    You could do it like this, which will return an array with the 2 names based on Ex.
    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. [SOLVED] Need the proper syntax to use Case/Select Case in vba properly.
    By rbion in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-16-2013, 02:34 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. Select Case stops after 1st case
    By skysurfer in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-02-2010, 04:25 PM
  5. Select case / case is, multiple arguments
    By Werner Rohrmoser in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-03-2006, 07:00 AM

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