Consulting

Results 1 to 7 of 7

Thread: Case Statement

  1. #1

    Case Statement

    Hey all,

    Curious how this statement will work. F13 calls sub test1 and the next line test 2. Will both the subs be called or will it stop at test1? Seems like it only runs test 1. Im guessing I should change the code and put test 1 and test 2 under F13.

    Thanks much

    [VBA]
    private Sub Worksheet_Change(ByVal Target As Range)
    On Error GoTo Exits
    Application.EnableEvents = False
    Select Case Target.Address

    Case "$F$13"
    Call test1

    Case "$F$8", "$F$9", "$F$13", "$E$13"
    Call test 2

    Case "$F$12"
    Call test3



    End Select
    Exits:
    Application.EnableEvents = True
    End Sub
    [/VBA]

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    It will stop at test1, but why would you expect otherwise, Target cannot be F13 and E13 (it could be E13:F13 but that is another matter).
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Ok...so this seems to work. F13 now calls both subs and they run.


    Dont understand what you mean here

    "Target cannot be F13 and E13 (it could be E13:F13 but that is another matter). "

    [VBA]
    Private Sub Worksheet_Change(ByVal Target As Range)
    On Error GoTo Exits
    Application.EnableEvents = False
    Select Case Target.Address

    Case "$F$13"
    Call test1
    Call test2

    Case "$F$8", "$F$9", "$E$13"
    Call test2

    Case "$F$12"
    Call test3




    End Select
    Exits:
    Application.EnableEvents = True
    End Sub
    [/VBA]

  4. #4
    VBAX Tutor lynnnow's Avatar
    Joined
    Jan 2005
    Location
    Mumbai, Maharashtra, India
    Posts
    299
    Location
    Quote Originally Posted by gimli
    Dont understand what you mean here

    "Target cannot be F13 and E13 (it could be E13:F13 but that is another matter). "
    It means if you want a particular code to run on a selection of more than one cell it will have to be E13:F13. F13 and E13 will be two separate cell selections.

  5. #5
    ok thanks

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by gimli
    Ok...so this seems to work. F13 now calls both subs and they run.


    Dont understand what you mean here

    "Target cannot be F13 and E13 (it could be E13:F13 but that is another matter). "
    What I mean is that you can select a single cell, in which case Target.Address is that single cell, such as $F$13, or you can select multiple cells, such as E13 and F13, in which case Target.Address is $E$13:$F$13, or multiple cells such as E13 and G9, in which case Target.Address is $E$13,$G$9. You have to allow for all cases, or else reject multiple selections.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    Ok thanks for reply.

Posting Permissions

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