IF with ElseIF

jose001

Board Regular
Joined
Mar 27, 2006
Messages
103
Hi Guys,

Does anyone have any idea what I'm doing wrong here please, have re-written this code every way I can imagine. What am I missing?

Code:
Private Sub CommandButton1_Click()
Dim x As Integer
x = TextBox1.Value

If x <= 99 Then TextBox2.Value = 125
ElseIf x <= 499 And x >= 100 Then TextBox2.Value = 600
ElseIf x <= 999 And x >= 500 Then TextBox2.Value = 1250
ElseIf x <= 4999 And x >= 1000 Then TextBox2.Value = 2500
ElseIf x <= 9999 And x >= 5000 Then TextBox2.Value = 3500
ElseIf x <= 24999 And x >= 10000 Then TextBox2.Value = 4000
ElseIf x >= 10001 Then TextBox2.Value = 5000
End If

End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Try:
Code:
Private Sub CommandButton1_Click()
Dim x As Integer
x = Val(TextBox1)
If x <= 99 Then
TextBox2.Value = 125
ElseIf x <= 499 And x >= 100 Then
TextBox2.Value = 600
ElseIf x <= 999 And x >= 500 Then
TextBox2.Value = 1250
ElseIf x <= 4999 And x >= 1000 Then
TextBox2.Value = 2500
ElseIf x <= 9999 And x >= 5000 Then
TextBox2.Value = 3500
ElseIf x <= 24999 And x >= 10000 Then
TextBox2.Value = 4000
ElseIf x >= 10001 Then
TextBox2.Value = 5000
End If
End Sub
I just modified something here..
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,827
Members
452,946
Latest member
JoseDavid

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