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

OilEconomist

Active Member
Joined
Dec 26, 2016
Messages
417
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

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

easy2understandexcel

Active Member
Joined
Dec 26, 2012
Messages
299
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

OilEconomist

Active Member
Joined
Dec 26, 2016
Messages
417
Office Version
  1. 2019
Platform
  1. Windows
Apologies for the late response.

Thanks as this fixed it. I always get mixed on my ().
 
Upvote 0

Forum statistics

Threads
1,190,786
Messages
5,982,913
Members
439,807
Latest member
WXM86

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
Top