ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   It Then Else Question (https://www.excelbanter.com/excel-programming/434593-then-else-question.html)

William Wolfe

It Then Else Question
 
What is wrong with the following code? I get a compile error 'Else without
IF"

If LinkBudget.Range("E143") < -14 Then
Detail_Report.Cells(61, Column).Select
With Selection.Interior
.Color = 6750105
Else
Detail_Report.Cells(61, Column).Select
With Selection.Interior
.Color = 255
End If

Thanks,

W Wolfe



Mike H

It Then Else Question
 
Hi,

It's actually the WITH statement giving the error, there's no END WITH. Try
this

If LinkBudget.Range("E143") < -14 Then
Detail_Report.Cells(61, Column).Select
With Selection.Interior
.Color = 6750105
End With
Else
Detail_Report.Cells(61, Column).Select
With Selection.Interior
.Color = 255
End With
End If

Mike

"William Wolfe" wrote:

What is wrong with the following code? I get a compile error 'Else without
IF"

If LinkBudget.Range("E143") < -14 Then
Detail_Report.Cells(61, Column).Select
With Selection.Interior
.Color = 6750105
Else
Detail_Report.Cells(61, Column).Select
With Selection.Interior
.Color = 255
End If

Thanks,

W Wolfe




Rick Rothstein

It Then Else Question
 
You are missing the two End With statements that are needed to close the two
With statements that you created (although you can easily eliminate them as
you only reference back to them one time each). As to why the "Else with If"
message... VB looks to close all statements that require a closing pair
(If..End If, Do..Loop, Select Case..End Select, etc.)... if it is missing
one or more, it just generates a compile error message of what it **thinks**
it could be, but it doesn't analyze the actual structure to see what is
actually missing; so you shouldn't focus on the wording of the message as
much as on the fact that the message was issued, then start looking for a
missing closing statement of some kind.

--
Rick (MVP - Excel)


"William Wolfe" wrote in message
...
What is wrong with the following code? I get a compile error 'Else
without IF"

If LinkBudget.Range("E143") < -14 Then
Detail_Report.Cells(61, Column).Select
With Selection.Interior
.Color = 6750105
Else
Detail_Report.Cells(61, Column).Select
With Selection.Interior
.Color = 255
End If

Thanks,

W Wolfe



William Wolfe

It Then Else Question
 
Thanks to all.

W. Wolfe

"Mike H" wrote in message
...
Hi,

It's actually the WITH statement giving the error, there's no END WITH.
Try
this

If LinkBudget.Range("E143") < -14 Then
Detail_Report.Cells(61, Column).Select
With Selection.Interior
.Color = 6750105
End With
Else
Detail_Report.Cells(61, Column).Select
With Selection.Interior
.Color = 255
End With
End If

Mike

"William Wolfe" wrote:

What is wrong with the following code? I get a compile error 'Else
without
IF"

If LinkBudget.Range("E143") < -14 Then
Detail_Report.Cells(61, Column).Select
With Selection.Interior
.Color = 6750105
Else
Detail_Report.Cells(61, Column).Select
With Selection.Interior
.Color = 255
End If

Thanks,

W Wolfe






Dana DeLouis

It Then Else Question
 
Detail_Report.Cells(61, Column).Select

Hi. Instead of selecting, would something like this help?

Detail_Report.Cells(61, Column).Interior.Color = _
IIf(LinkBudget.Range("E143") < -14, 6750105, 255)

= = = = = = = = = =
HTH :)
Dana DeLouis



On 10/6/09 12:27 PM, William Wolfe wrote:
Thanks to all.

W. Wolfe

"Mike wrote in message
...
Hi,

It's actually the WITH statement giving the error, there's no END WITH.
Try
this

If LinkBudget.Range("E143")< -14 Then
Detail_Report.Cells(61, Column).Select
With Selection.Interior
.Color = 6750105
End With
Else
Detail_Report.Cells(61, Column).Select
With Selection.Interior
.Color = 255
End With
End If

Mike

"William Wolfe" wrote:

What is wrong with the following code? I get a compile error 'Else
without
IF"

If LinkBudget.Range("E143")< -14 Then
Detail_Report.Cells(61, Column).Select
With Selection.Interior
.Color = 6750105
Else
Detail_Report.Cells(61, Column).Select
With Selection.Interior
.Color = 255
End If

Thanks,

W Wolfe








All times are GMT +1. The time now is 04:26 PM.

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