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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
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,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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