Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
Convert text to number
I am using an input box to assign a number to a variable. e.g
EC = InputBox("Enter the number of the Position Description from the list below." ) However, I think if the input is say 13, the variable stores this as a text "13". 1. Am I correct in assuming this? 2. Can I convert this from text to a number with code? Any assistance would be appreciated. |
#2
Posted to microsoft.public.excel.misc
|
|||
|
|||
Convert text to number
The number entered should be a number.
Sub qwer() Dim asdf as Long asdf = InputBox("enter a number") Range("H1").Value = asdf End Sub H1 is number 13 after running the above and entering 13 in the inputbox. Gord Dibben MS Excel MVP On Thu, 25 Oct 2007 18:43:02 -0700, GrantW wrote: I am using an input box to assign a number to a variable. e.g EC = InputBox("Enter the number of the Position Description from the list below." ) However, I think if the input is say 13, the variable stores this as a text "13". 1. Am I correct in assuming this? 2. Can I convert this from text to a number with code? Any assistance would be appreciated. |
#3
Posted to microsoft.public.excel.misc
|
|||
|
|||
Convert text to number
Yes, the inputbox function returns text. If EC is declared as a numeric
type, vba would coerce the input to a number by itself. Dim EC As Long EC = Inputbox(....) Or, you can explicitly convert the input EC = Clng(Inputbox(..)) However, you would get an error if text was input that could not be converted to numeric unless you tested it using IsNumeric first Dim EC As Variant EC = Inputbox(...) If IsNumeric(EC) Then EC = Clng(EC) Or use the Inputbox method, which allows you to specify the type of data that can be input. EC = Application.Inputbox(Prompt:="Input", Type:=1) "GrantW" wrote: I am using an input box to assign a number to a variable. e.g EC = InputBox("Enter the number of the Position Description from the list below." ) However, I think if the input is say 13, the variable stores this as a text "13". 1. Am I correct in assuming this? 2. Can I convert this from text to a number with code? Any assistance would be appreciated. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Convert text number to number formate | Excel Discussion (Misc queries) | |||
convert number to text | Excel Worksheet Functions | |||
Convert Text to Number | Excel Worksheet Functions | |||
convert text-format number to number in excel 2000%3f | Excel Discussion (Misc queries) | |||
not able to convert text, or graphic number to regular number in e | Excel Worksheet Functions |