+ Reply to Thread
Results 1 to 6 of 6

Select Case with multiple lines in a case statement?

  1. #1
    Registered User
    Join Date
    03-20-2017
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    11

    Question Select Case with multiple lines in a case statement?

    I'm new to VBA, and working in Excel. I'd like to use a Select Case statement, but all of the examples I find are very simplistic; one line of code in any case statemenet. What notation or syntax should I use if I want to have multiple lines of code in a case statement? For example, in the first case statement below, I added several lines of "code". Do I need parens or anything like that?

    I realize this is a really n00b question, but I couldn't find anything when I searched because the terms are pretty vague.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Select Case with multiple lines in a case statement?

    Why don't you just simply test with a couple of lines of code...?

  3. #3
    Registered User
    Join Date
    03-20-2017
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    11

    Re: Select Case with multiple lines in a case statement?

    Quote Originally Posted by cytop View Post
    Why don't you just simply test with a couple of lines of code...?
    Who says I'm not already doing extensive testing?

    Also, in this case, the testing will also change based on the case statement.

  4. #4
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Select Case with multiple lines in a case statement?

    Who says I'm not already doing extensive testing
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    03-20-2017
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    11

    Re: Select Case with multiple lines in a case statement?

    OK, so I was totally expecting my code to fail with some cryptic and useless error, but with multiple lines of code in the case statements, things work fine. There is no need for parens or any other notation in the cases. Comments are fine too.

    I don't know if there is an upper limit, but I have 27 lines in my first case statement and it works fine.

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2411
    Posts
    26,739

    Re: Select Case with multiple lines in a case statement?

    Quote Originally Posted by jGKpZ8a33sPrnqX8fam7 View Post
    OK, so I was totally expecting my code to fail with some cryptic and useless error, but with multiple lines of code in the case statements, things work fine. There is no need for parens or any other notation in the cases. Comments are fine too.

    I don't know if there is an upper limit, but I have 27 lines in my first case statement and it works fine.
    There is no limit.

    You can find details of the syntax of the Select statement on Microsoft pages. Although the example they gave is unfortunately trivial, the syntax does show that multiple statements are allowed.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

+ 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] is if-then or select case statement with multiple arguments possible?
    By kjy1989 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-03-2013, 02:54 AM
  2. [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
  3. Replies: 4
    Last Post: 05-06-2013, 11:06 AM
  4. [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
  5. Select case instead of if statement formula in multiple cells (macro)
    By city in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-25-2012, 07:56 AM
  6. 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
  7. [SOLVED] 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