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

#### OilEconomist

##### Active Member

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
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

#### OilEconomist

##### Active Member
Apologies for the late response.

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

#### easy2understandexcel

##### Active Member
Glad it worked! Thanks for the confirmation

Replies
0
Views
97
Replies
3
Views
68
Replies
0
Views
88
Replies
1
Views
103
Replies
8
Views
91

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.

### Which adblocker are you using?

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

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