VBA Case Select Multiple Conditions

I3atnumb3rs

New Member
Joined
Nov 2, 2018
Messages
34
Hello,

I'm trying to do a case statement in VBA. If the value in J is >= 200 AND <300 I want it to say in O REGULAR DELIVERY PV, when >= 300 AND <400 I want it to say REGULAR DELIVERY PV300, and when >= 400 REGULAR DELIVERY PV400. This does not work.

Sub VolumeChange()


'
Application.ScreenUpdating = False

'Changes delivery type


Dim x As Long

For x = 2 To Cells(Rows.Count, "J").End(xlUp).Row
Select Case UCase(Cells(x, 10))

Case Is >= 198
Cells(x, 15).FormulaR1C1 = "REGULAR DELIVERY PV"
Case Is >= 300
Cells(x, 15).FormulaR1C1 = "REGULAR DELIVERY PV300"
Case Is >= 400
Cells(x, 15).FormulaR1C1 = "REGULAR DELIVERY PV400"

End Select
Next x

End Sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
You'll need to look for the largest value first.

Code:
Sub VolumeChange()




'
Application.ScreenUpdating = False


'Changes delivery type




Dim x As Long


For x = 2 To Cells(Rows.Count, "J").End(xlUp).Row
Select Case UCase(Cells(x, 10))


Case Is >= 400
Cells(x, 15).FormulaR1C1 = "REGULAR DELIVERY PV400"
Case Is >= 300
Cells(x, 15).FormulaR1C1 = "REGULAR DELIVERY PV300"
Case Is >= 198
Cells(x, 15).FormulaR1C1 = "REGULAR DELIVERY PV"


End Select
Next x


End Sub
 
Upvote 0
Another option
Code:
Sub VolumeChange()
   Dim x As Long
   Dim Vu As String
   
   For x = 2 To Cells(Rows.Count, "J").End(xlUp).Row
      Select Case Cells(x, 10)
         Case Is >= 400
            Vu = "REGULAR DELIVERY PV400"
         Case 300 To 400
            Vu = "REGULAR DELIVERY PV300"
         Case 200 To 300
            Vu = "REGULAR DELIVERY PV"
      End Select
         Cells(x, 15).Value = Vu
   Next x
End Sub
 
Upvote 0
If it's 350 then it's greater than 200 so that condition is met and you get the result. In the reverse it's not greater than 400, but greater than 300 so you get the result.
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,219
Members
452,619
Latest member
Shiv1198

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