Expected: Line Number or Label or Statement or End of Statement

scooke

New Member
Joined
Mar 5, 2010
Messages
22
I am getting the error:

Expected: Line Number or Label or Statement or End of Statement

I am using Excel 2007 and here is the code:

Code:
Sub GuessMyName()
    Msg = "Is your Name" & Application.UserName & "?"
    Ans = MsgBox(Msg, vbYesNo)
    If Ans= vbNo Then "Oh Never Mind"
    If Ans= vbYes Then "I am pretty Smart!"
End Sub

This code came from Chapter one of book so I had hoped not to hit a roadblock so soon! Maybe I picked the wrong book! Any help would be appreciated. I have turned off requiring that variables be initiated. I normally wouldn't do that but this is a pretty simple test (at least I thought so). Thanks so much.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
I am getting the error:

Expected: Line Number or Label or Statement or End of Statement

I am using Excel 2007 and here is the code:

Code:
Sub GuessMyName()
    Msg = "Is your Name" & Application.UserName & "?"
    Ans = MsgBox(Msg, vbYesNo)
    If Ans= vbNo Then [B][COLOR=#b22222]"Oh Never Mind"[/COLOR][/B]
    If Ans= vbYes Then [B][COLOR=#b22222]"I am pretty Smart!"[/COLOR][/B]
End Sub

This code came from Chapter one of book so I had hoped not to hit a roadblock so soon! Maybe I picked the wrong book! Any help would be appreciated. I have turned off requiring that variables be initiated. I normally wouldn't do that but this is a pretty simple test (at least I thought so). Thanks so much.
The two text strings I highlighted in red cannot just stand alone like that... something has to be done with them (such as assign it to a variable or display it somewhere). My guess is you missed putting in the MsgBox function call so that the text strings would be displayed somewhere...

Code:
Sub GuessMyName()
    Msg = "Is your Name" & Application.UserName & "?"
    Ans = MsgBox(Msg, vbYesNo)
    If Ans= vbNo Then [B][COLOR=#b22222]MsgBox [/COLOR][/B][COLOR=#000000]"Oh Never Mind"[/COLOR]
    If Ans= vbYes Then [B][COLOR=#b22222]MsgBox[/COLOR][/B] [COLOR=#000000]"I am pretty Smart!"[/COLOR]
End Sub
 
Upvote 0
Hi Rick,

Thanks for the reply so quickly. I just double checked my book and I have typed that our verbatim which is pretty sad. Being such a rookie, I'd hate to ask but how would you suggest I do what I am attempting to do? Thanks again...
 
Upvote 0
Sorry Rick,

Now I see that you did show an example and after checking my book, it appears I am the idiot as I missed that. Thanks again for your help!
 
Upvote 0

Forum statistics

Threads
1,223,314
Messages
6,171,393
Members
452,398
Latest member
InvoicingNoob

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top