If then ElseIf Loop with Text and =< and >=.

OilEconomist

Active Member
Joined
Dec 26, 2016
Messages
421
Office Version
  1. 2019
Platform
  1. Windows
Thanks in advance for your assistance.

I am building an if then elseif else loop. I think the issue is the Else if because I want it to meet three criteria:

(1) Column A = 2000
(2) Column M = Blank
(3) Column H's value is in between or equal to these two account numbers 454001 and 540021 and is inclusive of both numbers. These are stored as text.

Please note all three of these conditions must be met on the second condition.

ElseIf (UCase(Cells(i, 1) = "2000") And UCase(Cells(i, 13) = "")) And (UCase(Cells(i, 8) >= "454001" And UCase(Cells(i, 18) =< "540021")) Then

I get "Compile error: Syntax error"

Code:
Sub Test()
            'Declares the column variables
                Dim i As Integer
                Dim LastRow1 As Long
                LastRow1 = ThisWorkbook.Worksheets("Raw.Data").Cells(Rows.Count, 1).End(xlUp).Row
     
                Worksheets("Raw.Data").Activate
                
                For i = 2 To LastRow1

                       If UCase(Cells(i, 1) = "2000") And UCase(Cells(i, 13) = "") And UCase(Cells(i, 12) = "101000") Then

                                    Cells(i, 29) = "Winner"

                       ElseIf (UCase(Cells(i, 1) = "2000") And UCase(Cells(i, 13) = "")) And (UCase(Cells(i, 18) >= "454001" And UCase(Cells(i, 18) =< "540021")) Then
                  
                                    Cells(i, 29) = "Winner"
   
 Else
                
End If
                
Next I

End Sub()
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
The error probably gave you a clue about your parentheses.
Try this :)

ElseIf UCase(Cells(i, 1) = "2000") And UCase(Cells(i, 13) = "") And UCase(Cells(i, 18)) >= "454001" And UCase(Cells(i, 18) <= "540021") Then
 
Upvote 0
Solution
Apologies for the late response.

Thanks as this fixed it. I always get mixed on my ().
 
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