Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Input Box

  Asked By: Adalicia    Date: Mar 20    Category: MS Office    Views: 696
  

I am a new user. I have "B9" cell that contains a certain string. I
want to use an IF statement that will look at "B9" and if the
string "Stationary" is in "B9" would set up a input box based on that
condition.

Also, can I have multiple lines in an input box or am I limited to just
one line?

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: ")

Any help will be appreciated.

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Lee Butler     Answered On: Mar 20

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

 
Answer #2    Answered By: Jennifer Davis     Answered On: Mar 20

I don't think you can throw a whole heap of statements in brackets at the
InputBox function like that. Try using

Then SCTCode = InputBox("1 = Underwater Structure" & vbcrlf & _
"2 = Feeding Structure" & vbcrlf & _
"3 = Transfer Structure" & vbcrlf & _
"4 = Fixed Structure" & vbcrlf & _
"5 = Custom Sturcture" & vbcrlf & _
"Enter Code 1 thru 5: ")

 
Didn't find what you were looking for? Find more on Input Box Or get search suggestion and latest updates.




Tagged: