Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Trouble with simple If and Else

Can someone tell me what's wrong with this? I keep getting the error "else without if"

Sub test()

Dim Msg, Style, Title

Msg = "Do you want to go ahead and continue setting up the individual store pages?"
Style = vbYesNo + vbCritical + vbDefaultButton2
Title = "Individual Store Pages"
Response = MsgBox(Msg, Style, Title)

If Response = vbYes Then GoTo Reports

Else

GoTo Endit

End If

Reports:

code

Endit:

more code

End Sub


TIA, Alan N
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Trouble with simple If and Else


you cant mix 1 line if then else with multiple line if then else

so either

if a=b then c else d

or

if a=b then
c
else
d
endif



keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"AlanN" wrote:

Can someone tell me what's wrong with this? I keep getting the error
"else without if"

Sub test()

Dim Msg, Style, Title

Msg = "Do you want to go ahead and continue setting up the individual
store pages?" Style = vbYesNo + vbCritical + vbDefaultButton2
Title = "Individual Store Pages"
Response = MsgBox(Msg, Style, Title)

If Response = vbYes Then GoTo Reports

Else

GoTo Endit

End If

Reports:

code

Endit:

more code

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Trouble with simple If and Else

The line

If Response = vbYes Then GoTo Reports

is complete i.e. this style does not need an End If.

This makes the Else line hang without a preceding If

You also need an Exit Sub before line Endit: otherwise,
the Endit: code will be executed as well.

Cleaner code:

Select case MsgBox(Msg, Style, Title)



end select

-----Original Message-----
Can someone tell me what's wrong with this? I keep

getting the error "else without if"

Sub test()

Dim Msg, Style, Title

Msg = "Do you want to go ahead and continue setting up

the individual store pages?"
Style = vbYesNo + vbCritical + vbDefaultButton2
Title = "Individual Store Pages"
Response = MsgBox(Msg, Style, Title)

If Response = vbYes Then GoTo Reports

Else

GoTo Endit

End If

Reports:

code

Endit:

more code

End Sub


TIA, Alan N

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Trouble with simple If and Else

Sub test()
Dim Msg, Style, Title
Msg = "Do you want to go ahead and continue setting" & _
" up the individual store pages?"
Style = vbYesNo + vbCritical + vbDefaultButton2
Title = "Individual Store Pages"
IF MsgBox(Msg, Style, Title)= vbYes then
' code for reports here
' or call a procedure
End If

''code here will execute always

End Sub


Using GOTO's is redundant as you'd code the'Yes' result
within the 'if - end if'. If the answer is anything other
than vbYes, the code continues after the 'end if'


Patrick Molloy
Microsoft Excel MVP


-----Original Message-----
Can someone tell me what's wrong with this? I keep

getting the error "else without if"

Sub test()

Dim Msg, Style, Title

Msg = "Do you want to go ahead and continue setting up

the individual store pages?"
Style = vbYesNo + vbCritical + vbDefaultButton2
Title = "Individual Store Pages"
Response = MsgBox(Msg, Style, Title)

If Response = vbYes Then GoTo Reports

Else

GoTo Endit

End If

Reports:

code

Endit:

more code

End Sub


TIA, Alan N

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Trouble with simple If and Else

Thanks, all responses are helpful.

AlanN
"AlanN" wrote in message ...
Can someone tell me what's wrong with this? I keep getting the error "else without if"

Sub test()

Dim Msg, Style, Title

Msg = "Do you want to go ahead and continue setting up the individual store pages?"
Style = vbYesNo + vbCritical + vbDefaultButton2
Title = "Individual Store Pages"
Response = MsgBox(Msg, Style, Title)

If Response = vbYes Then GoTo Reports

Else

GoTo Endit

End If

Reports:

code

Endit:

more code

End Sub


TIA, Alan N


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Trouble with simple If and Else

small modification
BUT SMART pls try this

PS. select case is a fast solution on the other hand it
gives you the possibility to use more options

Konrad

Sub test()

Dim Msg, Style, Title

Msg = "Do you want to go ahead and continue setting up the
individual store pages?"
Style = vbYesNo + vbCritical + vbDefaultButton2
Title = "Individual Store Pages"
Response = MsgBox(Msg, Style, Title)


Select Case Response

Case vbYes
'first code
MsgBox "vbYes"

Case vbNo
'secound code
MsgBox "vbNo"
End Select



End Sub


-----Original Message-----
Can someone tell me what's wrong with this? I keep

getting the error "else without if"

Sub test()

Dim Msg, Style, Title

Msg = "Do you want to go ahead and continue setting up

the individual store pages?"
Style = vbYesNo + vbCritical + vbDefaultButton2
Title = "Individual Store Pages"
Response = MsgBox(Msg, Style, Title)

If Response = vbYes Then GoTo Reports

Else

GoTo Endit

End If

Reports:

code

Endit:

more code

End Sub


TIA, Alan N

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Big Trouble with what I thought would be a simple Excel Formula Flip@work New Users to Excel 7 October 4th 08 09:06 PM
Simple problem, simple formula, no FUNCTION ! Ron@Buy Excel Worksheet Functions 6 September 28th 07 04:51 PM
TROUBLE WITH A SIMPLE FORMULA [email protected] Excel Discussion (Misc queries) 0 March 13th 07 08:33 PM
Trouble with simple percentage formula moushia New Users to Excel 3 February 28th 07 01:56 AM
Simple Formula Trouble FP Novice Excel Discussion (Misc queries) 3 August 4th 06 03:16 PM


All times are GMT +1. The time now is 11:24 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"