Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 17
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default 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   Report Post  
Posted to microsoft.public.excel.misc
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert text number to number formate [email protected] Excel Discussion (Misc queries) 2 April 9th 07 10:48 AM
convert number to text NAEEM Excel Worksheet Functions 6 December 6th 06 11:28 AM
Convert Text to Number CADManBill Excel Worksheet Functions 5 November 2nd 05 05:09 AM
convert text-format number to number in excel 2000%3f Larry Excel Discussion (Misc queries) 1 July 29th 05 08:18 PM
not able to convert text, or graphic number to regular number in e knutsenk Excel Worksheet Functions 1 April 2nd 05 08:41 AM


All times are GMT +1. The time now is 10:21 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"