View Full Version : [SOLVED:] Input Box
goldie12
07-11-2005, 08:01 AM
Hello
I trying to create an input box that will take the users multiple values and put them on a particular sheet in a specified range: I have the following code, but it is not working. Any suggestions:
Sub DisInput()
Dim varInput As Integer
Dim MyDis As Variant
varInput = InputBox("Please enter your distance range")
MyDis = Split(varInput, ",")
Sheets("Sheet 1").Range("A1:F1").Value = varInput
End Sub
Norie
07-11-2005, 08:14 AM
How is it not working?
Shouldn't this line
Sheets("Sheet 1").Range("A1:F1").Value = varInput
be this
Sheets("Sheet 1").Range("A1:F1").Value = MyDis
Bob Phillips
07-11-2005, 08:16 AM
Hello
I trying to create an input box that will take the users multiple values and put them on a particular sheet in a specified range: I have the following code, but it is not working. Any suggestions:
Sub DisInput()
Dim varInput As Integer
Dim MyDis As Variant
varInput = InputBox("Please enter your distance range")
MyDis = Split(varInput, ",")
Sheets("Sheet 1").Range("A1:F1").Value = varInput
End Sub
This works for me
Sub DisInput()
Dim varInput
Dim MyDis As Variant
varInput = InputBox("Please enter your distance range")
MyDis = Split(varInput, ",")
Sheets("Sheet1").Range("A1:F1").Value = MyDis
End Sub
Kinky Friedman as governor - streuth!
Killian
07-11-2005, 08:21 AM
Hi there,
"not working" doesn't really describe the nature of your problem - you'll get better help and advice quicker if you provide relevant details.
However, there are a couple of things:
Since you're splitting the input with commas I assume that the user will put in a comma delimited string for you to work with. So varInput will need to be a string.
Split returns an array to MyDis needs to be an array of type String
Then in the last line you need to assign that array to your range's value
Sub DisInput()
Dim varInput As String
Dim MyDis() As String
varInput = InputBox("Please enter your distance range")
MyDis = Split(varInput, ",")
Sheets("Sheet1").Range("A1:F1").Value = MyDis()
End Sub
goldie12
07-11-2005, 08:28 AM
The values are being stored as text and the user should only be able to enter numbers not text. Also, if the user only enters two numbers the code then enters N/A# in the remaining cells of the range. Is there a way to just leave blank?
Bob Phillips
07-11-2005, 08:41 AM
The values are being stored as text and the user should only be able to enter numbers not text. Also, if the user only enters two numbers the code then enters N/A# in the remaining cells of the range. Is there a way to just leave blank?
Sub DisInput()
Dim varInput
Dim MyDis As Variant
varInput = InputBox("Please enter your distance range")
MyDis = Split(varInput, ",")
With Sheets("Sheet1").Range("A1:F1")
.Value = MyDis
.Value = .Value
.Replace What:="#N/A", Replacement:=""
End With
End Sub
goldie12
07-11-2005, 08:56 AM
Thank you all very much.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.