Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Big Trouble with what I thought would be a simple Excel Formula | New Users to Excel | |||
Simple problem, simple formula, no FUNCTION ! | Excel Worksheet Functions | |||
TROUBLE WITH A SIMPLE FORMULA | Excel Discussion (Misc queries) | |||
Trouble with simple percentage formula | New Users to Excel | |||
Simple Formula Trouble | Excel Discussion (Misc queries) |