ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Getting error using if then else stmt (https://www.excelbanter.com/excel-worksheet-functions/159499-getting-error-using-if-then-else-stmt.html)

UB

Getting error using if then else stmt
 
Hi
I am using the follwoing code,
For rwIndex 4 to 100
If Month(Worksheets("Sheet1").Cells(rwIndex, 12).Value) _
Month(Mydate) Then .Interior.Color = RGB(255, 0, 0)
ElseIf Month(Worksheets("Sheet1").Cells(rwIndex, 12).Value) = "" Then
Worksheets("Sheet1").Cells(rwIndex, 12).Interior.Color = 2
Else
Worksheets("Sheet1").Cells(rwIndex, 12).Interior.Color = 2
End If


System gives me 'Complie Error'
Else without if.


Please advise, what is wrong with my code



JW[_2_]

Getting error using if then else stmt
 
Probably giving you an arbitrary error. Looks like the real problem
is in you For syntax.
For rwIndex 4 to 100 shoudl be For rwIndex = 4 to 100
ub wrote:
Hi
I am using the follwoing code,
For rwIndex 4 to 100
If Month(Worksheets("Sheet1").Cells(rwIndex, 12).Value) _
Month(Mydate) Then .Interior.Color = RGB(255, 0, 0)
ElseIf Month(Worksheets("Sheet1").Cells(rwIndex, 12).Value) = "" Then
Worksheets("Sheet1").Cells(rwIndex, 12).Interior.Color = 2
Else
Worksheets("Sheet1").Cells(rwIndex, 12).Interior.Color = 2
End If


System gives me 'Complie Error'
Else without if.


Please advise, what is wrong with my code



eliano

Getting error using if then else stmt
 
Hi ub.
If Month(Worksheets("Sheet1").Cells(rwIndex, 12).Value) _
Month(Mydate) Then .Interior.Color = RGB(255, 0, 0)

If and Then on the same row, end the IF instruction.

For rwindex = 4 To 100
If Month(Cells(rwindex, 12).Value) Month(Mydate) Then
Cells(rwindex, 12).Interior.Color = RGB(255, 0, 0)
ElseIf Month(Cells(rwindex, 12).Value) = "" Then
Cells(rwindex, 12).Interior.ColorIndex = 6
Else
Cells(rwindex, 12).Interior.ColorIndex = 6
End If
Next

Regards
Eliano



"ub" wrote:

Hi
I am using the follwoing code,
For rwIndex 4 to 100
If Month(Worksheets("Sheet1").Cells(rwIndex, 12).Value) _
Month(Mydate) Then .Interior.Color = RGB(255, 0, 0)
ElseIf Month(Worksheets("Sheet1").Cells(rwIndex, 12).Value) = "" Then
Worksheets("Sheet1").Cells(rwIndex, 12).Interior.Color = 2
Else
Worksheets("Sheet1").Cells(rwIndex, 12).Interior.Color = 2
End If


System gives me 'Complie Error'
Else without if.


Please advise, what is wrong with my code




All times are GMT +1. The time now is 07:50 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com