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

Thread: If statement

  1. #1
    New Member
    Join Date
    May 2002
    Location
    Baltimore
    Posts
    29
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Here is the code:

    With Sheets("Order Table").Range("B" & intcurrentrow)
    If lstOrderType = "Delivery" Then
    .Value = "Delivery"
    ElseIf lstOrderType = "Carry-Out" Then
    .Value = "Carry-Out"
    Else
    .Value = "Eat-In"
    End If
    End With

    The only value i get in the range is Eat-In.

  2. #2
    Board Regular
    Join Date
    Apr 2002
    Posts
    115
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I tried your code and it worked for me. Are you sure you are passing the right variable names (spelled correctly, right number of spaces...)?

  3. #3
    New Member
    Join Date
    May 2002
    Location
    Baltimore
    Posts
    29
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Yes, here is my updated code, still getting "Eat-In" for value in range.

    With Sheets("Order Table").Range("B" & intcurrentrow)
    If cboOrderType = "Delivery" Then
    .Value = "Delivery"
    ElseIf cboOrderType = "Carry-Out" Then
    .Value = "Carry-Out"
    Else
    .Value = "Eat-In"
    End If
    End With

  4. #4
    Board Regular
    Join Date
    Apr 2002
    Posts
    115
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    On 2002-05-07 09:33, TheMatrixReloaded wrote:
    Yes, here is my updated code, still getting "Eat-In" for value in range.

    With Sheets("Order Table").Range("B" & intcurrentrow)
    If cboOrderType = "Delivery" Then
    .Value = "Delivery"
    ElseIf cboOrderType = "Carry-Out" Then
    .Value = "Carry-Out"
    Else
    .Value = "Eat-In"
    End If
    End With
    When you say you only get "Eat-In" for a value, do you mean in every case? If that's the case, then you must not be passing a correct value for "Delivery" or "Carry-Out". Have you tried setting a watch on the cboOrderType variable to check what the value is?

  5. #5
    Board Regular
    Join Date
    Apr 2002
    Posts
    115
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I noticed in your code that cboOrderType could equal any value besides "Dinner" and Carry-Out" and it would place "Eat-In" in the range. It never checks to see what happens if it says something else. Try this replacement code:

    With Sheets("Order Table").Range("B" & intcurrentrow)
    If lstOrderType = "Delivery" Then
    .Value = "Delivery"
    ElseIf lstOrderType = "Carry-Out" Then
    .Value = "Carry-Out"
    ElseIf lstOrderType = "Eat-In" Then
    .Value = "Eat-In"
    Else
    .Value = "Incorrect Value"
    End If
    End With

  6. #6
    New Member
    Join Date
    May 2002
    Location
    Baltimore
    Posts
    29
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Now it comes up with "Incorrect Value", so its skipping through all the other if's, and going straight to the last one. I can't figure it out. I can send u the file if you want to look at it first hand.

  7. #7
    Board Regular
    Join Date
    Apr 2002
    Posts
    115
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Why don't you place a watch on cboOrderType and place a breakpoint at the first 'IF' statement. It will show you what value is assigned to "cboOrderType". I really believe this is the problem. "cboOrderType" is not the value you think it is. It might be something simple as an extra space.

  8. #8
    Legend NateO's Avatar
    Join Date
    Feb 2002
    Location
    Minneapolis, Mn, USA
    Posts
    9,700
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    It may not be incorrect in the file that's one the way...Should be careful how many people you get cracking on this at one time, it's not considerate to have 30 people all reinventing the wheel at once.

    _________________
    Cheers, NateO

    [ This Message was edited by: NateO on 2002-05-07 12:11 ]

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
  •