If statement

TheMatrixReloaded

New Member
Joined
May 6, 2002
Messages
29
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.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
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...)?
 
Upvote 0
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
 
Upvote 0
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?
 
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0
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,<font size=+2><font color="red"> Nate<font color="blue">O</font></font></font>
wave.gif

This message was edited by NateO on 2002-05-07 12:11
 
Upvote 0

Forum statistics

Threads
1,213,538
Messages
6,114,217
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top