Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 5 of 5

Thread: If...Elseif msgbox statements

  1. #1
    Board Regular
    Join Date
    Apr 2002
    Location
    Alberta, Canada
    Posts
    50
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    why is this not working?

    Private Sub OK_Click()
    If CC Then MsgBox ("You have selected Cost Center")
    If CC_Prime Then MsgBox ("You have selected Prime")
    Else
    MsgBox ("You must click either Cost Center or Cost Center and Primes")
    End


    [ This Message was edited by: excelmacro on 2002-04-25 08:41 ]

    [ This Message was edited by: excelmacro on 2002-05-03 12:23 ]

  2. #2
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Sunny, spring-like Hull
    Posts
    3,339
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Try this, you needed to use a block If..Then..Else: -

    Private Sub OK_Click()
    If CC Then MsgBox ("You have selected Cost Center")
    If CC_Prime Then
    MsgBox ("You have selected Prime")
    Else
    MsgBox ("You must click either Cost Center or Cost Center and Primes")
    End
    End If
    End Sub

  3. #3
    Board Regular
    Join Date
    Apr 2002
    Location
    Alberta, Canada
    Posts
    50
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    now when i click on CC and then hit the ok button, it comes up with the msgbox "You have selected Cost Center" response, and then the msgbox "You must click either the Cost Center or Cost Center and Primes". It works fine though when i only check on CC_Prime or don't check either of CC or CC_Prime

  4. #4
    MrExcel MVP Jay Petrulis's Avatar
    Join Date
    Mar 2002
    Location
    Chicago, IL USA
    Posts
    2,040
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Try,

    Private Sub OK_Click()
    If CC Then
    MsgBox ("You have selected Cost Center")
    ElseIf CC_Prime Then
    MsgBox ("You have selected Prime")
    Else
    MsgBox ("You must click either Cost Center or Cost Center and Primes")
    End If
    End Sub

  5. #5
    Board Regular
    Join Date
    Apr 2002
    Location
    Alberta, Canada
    Posts
    50
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Thanks. Works great.

Some videos you may like

User Tag List

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
  •