if statement help in vba (1 Viewer)

virencm

Registered User.
Local time
Today, 17:35
Joined
Nov 13, 2009
Messages
61
Hi

New to VBA , Can some one please correct the code below. I ve heard that a select case statement might be even better then using If case statments. can you also please show me how to use the case statement for the code below? Thank you


If Left(Me.Engine, 1) = 6 Then
Engine_Type.Value = "PMC"

Else if Left(Me.Engine, 1) = 7 Then
Engine_Type.Value = "FADEC"

else
msgbox " Engine serial does not match engine type "

End If
End If
 

PNGBill

Win10 Office Pro 2016
Local time
Today, 19:35
Joined
Jul 15, 2008
Messages
2,271
Start by removing 2nd End If otherwise syntax appears correct.

Have you verified the data is as expected?
 

virencm

Registered User.
Local time
Today, 17:35
Joined
Nov 13, 2009
Messages
61
There was a space between else and if. Thanks vbaInet.
 

vbaInet

AWF VIP
Local time
Today, 08:35
Joined
Jan 22, 2010
Messages
26,374
Glad we could help.

If only all programming languages kept to one way of writing ElseIf. I prefer Else If (with a space) which some other languages use.
 

Users who are viewing this thread

Top Bottom