teaching myself vba please help

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
 
T

Trevor Shuttleworth

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
 
N

Niek Otten

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
|
|
 
Top