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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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,214,979
Messages
6,122,551
Members
449,088
Latest member
davidcom

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