: Why doesn't VBA like this line of code? I get a "Type Mismatch Error
: 13" when I try to run.
: If Worksheets("Input").Range("B9").Text = "Stationary" _
: Then SCTCode = InputBox("1 = Underwater Structure") _
: ("2 = Feeding Structure") _
: ("3 = Transfer Structure") _
: ("4 = Fixed Structure") _
: ("5 = Custom Sturcture") _
: ("Enter code 1 thru 5: ")
Do more testing. Use the VBA help system. Combine successfully
tested simple statements to form complex statements.
Test this (all one line):
InputBox("1 = Underwater Structure") ("2 = Feeding Structure") ("3 =
Transfer Structure") ("4 = Fixed Structure") ("5 = Custom Structure")
("Enter Code 1 thru 5: ")
It doesn't work on a single line, so it will not work
on multiple lines. Place the cursor inside the word
"InputBox" and press the F1 function key. VBA help reveals
the syntax for InputBox uses only one set of parenthesis,
not six sets. It also tells how to insert more than one
line, though it omits describing the vbCrLf constant.
Here's a working InputBox.
InputBox ( _
"1 = Underwater Structure" & vbCrLf & _
"2 = Feeding Structure" & vbCrLf & _
"3 = Transfer Structure" & vbCrLf & _
"4 = Fixed Structure" & vbCrLf & _
"5 = Custom Structure" & vbCrLf & vbCrLf & _
"Enter Code 1 thru 5:" _
)
After testing this, I can then place it into the
conditional, confident that an error will not be caused
by the input box.
If Worksheets("Input").Range("B9").Text = "Stationary" Then
SCTCode = InputBox( _
"1 = Underwater Structure" & vbCrLf & _
"2 = Feeding Structure" & vbCrLf & _
"3 = Transfer Structure" & vbCrLf & _
"4 = Fixed Structure" & vbCrLf & _
"5 = Custom Structure" & vbCrLf & vbCrLf & _
"Enter Code 1 thru 5:" _
)
End If