teaching myself vba please help

  • Thread starter Thread starter Paul H
  • Start date Start date
P

Paul H

I am trying to teach myself VBA and have just been pulling my hair out with
the following:

Public Sub name1()
Dim x As String
x = InputBox("Enter your name:")
If x = Paul Then MsgBox ("Hello, Paul")
ElseIf x <> Paul Then MsgBox ("Hello" & x)
End If
End Sub

Everytime I debug using F8 I get an error message saying Else without If. I
know I am only learning but surely there is an If at the start of line 4.
The help info is not much help as it seems to say the problem is before the
indicated problem, but I can't see it. So to stop an old man going mad can
you please help and explain what I am doing wrong.
Sorry didnt realise that if the subject matched an already active subject it
was posted there instead of being a new one
 
Try:

Public Sub name1()
Dim x As String
x = InputBox("Enter your name:")
If x = "Paul" Then
MsgBox ("Hello, Paul")
ElseIf x <> "Paul" Then
MsgBox ("Hello " & x)
End If
End Sub

Regards

Trevor
 
Public Sub name1()
Dim x As String
x = InputBox("Enter your name:")
If x = "Paul" Then MsgBox ("Hello, Paul") Else: MsgBox ("Hello " & x)
End Sub

--
Kind regards,

Niek Otten
Microsoft MVP - Excel


|I am trying to teach myself VBA and have just been pulling my hair out with
| the following:
|
| Public Sub name1()
| Dim x As String
| x = InputBox("Enter your name:")
| If x = Paul Then MsgBox ("Hello, Paul")
| ElseIf x <> Paul Then MsgBox ("Hello" & x)
| End If
| End Sub
|
| Everytime I debug using F8 I get an error message saying Else without If. I
| know I am only learning but surely there is an If at the start of line 4.
| The help info is not much help as it seems to say the problem is before the
| indicated problem, but I can't see it. So to stop an old man going mad can
| you please help and explain what I am doing wrong.
| Sorry didnt realise that if the subject matched an already active subject it
| was posted there instead of being a new one
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top