Thanks Thanks:  0
Likes Likes:  0
Results 1 to 7 of 7

Thread: how does the case comand work

  1. #1
    Board Regular
    Join Date
    Feb 2012
    Location
    Central Coast NSW Australia
    Posts
    259
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default how does the case comand work

    I see answers to problems using 'case' , I think this is exactly what I need , but I don't know how to set it up and the syntax, does the case have numeric values or can they be text. I'm hoping to avoid nested if's , maybe even nested ifs within nested ifs

  2. #2
    MrExcel MVP VoG's Avatar
    Join Date
    Jun 2002
    Location
    127.0.0.1
    Posts
    63,651
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    7 Thread(s)

    Default Re: how does the case comand work

    HTH, Peter
    Please test any code on a copy of your workbook.

  3. #3
    Board Regular
    Join Date
    Feb 2012
    Location
    Central Coast NSW Australia
    Posts
    259
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: how does the case comand work

    Thanks Peter,
    just checking it out now

  4. #4
    Board Regular
    Join Date
    Nov 2009
    Posts
    4,768
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: how does the case comand work

    Excel's Help on the Select Case Statement is fairly good.
    There is one trick it doesn't mention, you can have the likes of:
    Code:
    Select Case True
       Case x=y
        'do something
       Case zz="Easter"
        do something else
       Case Month(Date)=12
        'do something
    End Select

  5. #5
    Board Regular
    Join Date
    Feb 2012
    Location
    Central Coast NSW Australia
    Posts
    259
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: how does the case comand work

    thanks P45cal,
    I never seem to get any real help from help, One more thing, can I have
    Code:
    case x=1 and zz = 3

  6. #6
    Board Regular
    Join Date
    Nov 2009
    Posts
    4,768
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: how does the case comand work

    As long as it evaluates to true or false, yes.
    (I'm not 100% sure you mean both x must equal 1 and zz equal 3
    or
    either x = 1 or zz =3.)

    Google can be helpful too:
    Select Case Statement in Excel VBA Macro Code. Alternative to Multiple If, Or, And Else Statements
    VBA Select Case – Using VBA Select Case Statement in Excel | Excel & VBA – Databison
    Select...Case Statement (Visual Basic)

  7. #7
    Board Regular
    Join Date
    Feb 2012
    Location
    Central Coast NSW Australia
    Posts
    259
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: how does the case comand work

    thanks p45cal,
    I meant If(x=1 and zz=3) then.... , I will look at all those links later. I tend to forget about google for this type of help, even though it was google that pointed me to mrexcel.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •