Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compile error: End If without block If

Status
Not open for further replies.

TFlanagan

MIS
Mar 19, 2009
8
US
Good afternoon everyone. I'm attempting to execute an If-Then-Else block of code. The compiler keeps blowing up; it cannot connect the different parts of my block. I've tried numerous changes with no result. Please help! Thank you.

my code:

If (MessageBox.Show("Are you using SPOT_IN transmission?", "PJM transmission type" _
, MessageBoxButtons.YesNo, MessageBoxIcon.Question) = _
Windows.Forms.DiagogResult.Yes) Then _
Range("I36:J36").Select: ActiveCell.FormulaR1C1 = "$0.74 on / $0.43 off" _
Else
Range("I36:J36").Select: ActiveCell.FormulaR1C1 = ("MISO: $0.74 on/$0.43 off; PJM: $0.67")
End If
 
Code:
If MsgBox("Are you using SPOT_IN transmission?", "PJM transmission type", vbYesNo, vbQuestion) = Windows.Forms.DiagogResult.Yes Then
    Range("I36:J36").Select: ActiveCell.FormulaR1C1 = "$0.74 on / $0.43 off"
  Else
    Range("I36:J36").Select: ActiveCell.FormulaR1C1 = ("MISO: $0.74 on/$0.43 off; PJM: $0.67")
End If
 



...and better yet...
Code:
If MsgBox("Are you using SPOT_IN transmission?", "PJM transmission type", vbYesNo, vbQuestion) = Windows.Forms.DiagogResult.Yes Then[b]
    Range("I36:J36").Value= "$0.74 on / $0.43 off"[/b]
  Else[b]
    Range("I36:J36").Value= ("MISO: $0.74 on/$0.43 off; PJM: $0.67")[/b]
...BUT

you are not assigning a FORMULA. Rather, you are assigning a STRING value.

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
If it is a copy/paste selection of your code, change a part of it to: Windows.Forms.Dia[!]l[/!]ogResult


combo
 
Thank you for the help everyone. I've incorporated the suggested changes. The routine will now compile however it still will not execute. I'm now getting a "Run-time error '424': Object Required" message. When I debug, it highlights the 'If' line of the If-Then-Else block.
Code:
If (MessageBox.Show("Are you using SPOT_IN transmission?", "PJM transmission type", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes) Then
    Range("I36:J36").Select: ActiveCell.Value = "$0.74 on / $0.43 off"
Else: Range("I36:J36").Select: ActiveCell.Value = ("MISO: $0.74 on/$0.43 off; PJM: $0.67")
End If
 
What syntax is that? In other words what application are you working in?
 
check out your parentheses compared to the examples others have posted.

[tt][blue]-John[/blue][/tt]
[tab][red]The plural of anecdote is not data[/red]

Help us help you. Please read FAQ 181-2886 before posting.
 
You're trying to use .Net code in VBA (messagebox.show and Windows.Forms.DialogResult.Yes), if you use the code by ettienne with two small adjustments (or Skip's code with the same adjustment:
Code:
If MsgBox("Are you using SPOT_IN transmission?", [red]vbYesNo+vbQuestion, "PJM transmission type"[/red]) = [red]vbYes[/red] Then
    Range("I36:J36").Select: ActiveCell.FormulaR1C1 = "$0.74 on / $0.43 off"
  Else
    Range("I36:J36").Select: ActiveCell.FormulaR1C1 = ("MISO: $0.74 on/$0.43 off; PJM: $0.67")
End If
The msgbox parameters were also in the wrong order.

Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.

 
The colon after the else statement won't cause a problem.

Cheers

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top