PC Review


Reply
Thread Tools Rate Thread

Help - Excel 97 Macro convert Text to Number

 
 
John Thomas Smith
Guest
Posts: n/a
 
      3rd Oct 2005
I have a monthly process where I bring a range of cells
into a spreadsheet (copy-paste) and I need the information
to be numbers but it is created (out of my control) as text

such as...
'1.23
'1.24
'1.25
and so on for about a hundred rows

It is really cumbersome to have to keep pressing F2 to edit,
home to get to the ' and then delete and enter to remove the
' mark and convert the text to a number

I used the Macro recorder (with relative value set) but it
picks up the absolute value of the first cell and then when I
run the macro it puts that value into each cell

What I want to do, but don't know how, is edit the macro so it
works on the current cell to go to the beginning of the cell
and remove the ' to make text into number, and then activate
the Enter key to go down to the next cell to be ready for me
to press Ctrl-t to run again (until the end of the data)

What I have from the macro recorder (plus my attempt to edit,
which does not work and stops with an error) is...

Sub Txt2Num()
'
' Txt2Num Macro
' Macro recorded 10/3/2005 by Mailroom
'
' Keyboard Shortcut: Ctrl+t
' ActiveCell.FormulaR1C1 = "1.23"
'
ActiveCell = Value(ActiveCell)
ActiveCell.Offset(1, 0).Range("A1").Select
End Sub

I **think** I need to do something with the Value command,
but it does not work

Could someone post the code to operate on the "activecell"
to go to the start of the cell and remove the ' so the text
entry will convert to numeric?

Thanks Much !!!

John Thomas Smith
http://www.direct2usales.com
http://www.pacifier.com/~jtsmith
 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      3rd Oct 2005
John,

Try this

Sub Txt2Num()
Dim i As Long

For i = 1 To Cells(Rows.Count,"A").End(xlUp)
Cells(i,"A").Value = Val(Cell(i,"A").Value)
Next i
End Sub

HTH
Bob

"John Thomas Smith" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have a monthly process where I bring a range of cells
> into a spreadsheet (copy-paste) and I need the information
> to be numbers but it is created (out of my control) as text
>
> such as...
> '1.23
> '1.24
> '1.25
> and so on for about a hundred rows
>
> It is really cumbersome to have to keep pressing F2 to edit,
> home to get to the ' and then delete and enter to remove the
> ' mark and convert the text to a number
>
> I used the Macro recorder (with relative value set) but it
> picks up the absolute value of the first cell and then when I
> run the macro it puts that value into each cell
>
> What I want to do, but don't know how, is edit the macro so it
> works on the current cell to go to the beginning of the cell
> and remove the ' to make text into number, and then activate
> the Enter key to go down to the next cell to be ready for me
> to press Ctrl-t to run again (until the end of the data)
>
> What I have from the macro recorder (plus my attempt to edit,
> which does not work and stops with an error) is...
>
> Sub Txt2Num()
> '
> ' Txt2Num Macro
> ' Macro recorded 10/3/2005 by Mailroom
> '
> ' Keyboard Shortcut: Ctrl+t
> ' ActiveCell.FormulaR1C1 = "1.23"
> '
> ActiveCell = Value(ActiveCell)
> ActiveCell.Offset(1, 0).Range("A1").Select
> End Sub
>
> I **think** I need to do something with the Value command,
> but it does not work
>
> Could someone post the code to operate on the "activecell"
> to go to the start of the cell and remove the ' so the text
> entry will convert to numeric?
>
> Thanks Much !!!
>
> John Thomas Smith
> http://www.direct2usales.com
> http://www.pacifier.com/~jtsmith



 
Reply With Quote
 
John Thomas Smith
Guest
Posts: n/a
 
      3rd Oct 2005
On Mon, 3 Oct 2005 11:28:57 -0700, "Bob Phillips"
<(E-Mail Removed)> wrote:

>Sub Txt2Num()
>Dim i As Long
>
> For i = 1 To Cells(Rows.Count,"A").End(xlUp)
> Cells(i,"A").Value = Val(Cell(i,"A").Value)
> Next i
>End Sub


Stopped with an error on Cell, so (not knowing what I am
doing) I changed to...

> Cells(i,"A").Value = Val(Cells(i,"A").Value)


That runs... but does not remove the ' at the start

I still wind up with '1.23 '1.24 '1.25 and so on in the
cells... did not remove the ' as I need


John Thomas Smith
http://www.direct2usales.com
http://www.pacifier.com/~jtsmith
 
Reply With Quote
 
Debra Dalgleish
Guest
Posts: n/a
 
      3rd Oct 2005
There are instructions here for converting text numbers to real numbers,
either manually or programmatically:

http://www.contextures.com/xlDataEntry03.html

John Thomas Smith wrote:
> I have a monthly process where I bring a range of cells
> into a spreadsheet (copy-paste) and I need the information
> to be numbers but it is created (out of my control) as text
>
> such as...
> '1.23
> '1.24
> '1.25
> and so on for about a hundred rows
>
> It is really cumbersome to have to keep pressing F2 to edit,
> home to get to the ' and then delete and enter to remove the
> ' mark and convert the text to a number
>
> I used the Macro recorder (with relative value set) but it
> picks up the absolute value of the first cell and then when I
> run the macro it puts that value into each cell
>
> What I want to do, but don't know how, is edit the macro so it
> works on the current cell to go to the beginning of the cell
> and remove the ' to make text into number, and then activate
> the Enter key to go down to the next cell to be ready for me
> to press Ctrl-t to run again (until the end of the data)
>
> What I have from the macro recorder (plus my attempt to edit,
> which does not work and stops with an error) is...
>
> Sub Txt2Num()
> '
> ' Txt2Num Macro
> ' Macro recorded 10/3/2005 by Mailroom
> '
> ' Keyboard Shortcut: Ctrl+t
> ' ActiveCell.FormulaR1C1 = "1.23"
> '
> ActiveCell = Value(ActiveCell)
> ActiveCell.Offset(1, 0).Range("A1").Select
> End Sub
>
> I **think** I need to do something with the Value command,
> but it does not work
>
> Could someone post the code to operate on the "activecell"
> to go to the start of the cell and remove the ' so the text
> entry will convert to numeric?
>
> Thanks Much !!!
>
> John Thomas Smith
> http://www.direct2usales.com
> http://www.pacifier.com/~jtsmith



--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html

 
Reply With Quote
 
Harlan Grove
Guest
Posts: n/a
 
      4th Oct 2005
John Thomas Smith wrote...
>I have a monthly process where I bring a range of cells
>into a spreadsheet (copy-paste) and I need the information
>to be numbers but it is created (out of my control) as text
>
>such as...
>'1.23
>'1.24
>'1.25
>and so on for about a hundred rows
>
>It is really cumbersome to have to keep pressing F2 to edit,
>home to get to the ' and then delete and enter to remove the
>' mark and convert the text to a number

....

You don't need a macro to do this if these are all in a single column.
Just select all cells in that column, issue the menu command Data >
Text to Columns and click on the Finish button.

>What I want to do, but don't know how, is edit the macro so it
>works on the current cell to go to the beginning of the cell
>and remove the ' to make text into number, and then activate
>the Enter key to go down to the next cell to be ready for me
>to press Ctrl-t to run again (until the end of the data)


If you must use a macro, try


Sub foo()
Dim i As Long

For i = 1 To Cells(Rows.Count, "A").End(xlUp).Row
With Cells(i, "A")
If Not IsEmpty(.Value) And IsNumeric(.Value) Then _
.Value = CDbl(.Value)
End With
Next i
End Sub

 
Reply With Quote
 
John Thomas Smith
Guest
Posts: n/a
 
      4th Oct 2005
On Mon, 03 Oct 2005 15:48:00 -0400, Debra Dalgleish
<(E-Mail Removed)> wrote:
>There are instructions here for converting text numbers to real numbers,
>either manually or programmatically:
> http://www.contextures.com/xlDataEntry03.html


Thanks DATA ==> TEXT TO COLUMNS did the job!

John Thomas Smith
http://www.direct2usales.com
http://www.pacifier.com/~jtsmith
 
Reply With Quote
 
John Thomas Smith
Guest
Posts: n/a
 
      4th Oct 2005
On 3 Oct 2005 15:10:39 -0700, "Harlan Grove" <(E-Mail Removed)> wrote:
>You don't need a macro to do this if these are all in a single column.
>Just select all cells in that column, issue the menu command Data >
>Text to Columns and click on the Finish button.


Thanks... works perfectly!

John Thomas Smith
http://www.direct2usales.com
http://www.pacifier.com/~jtsmith
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
convert text to number in excel The IC Teacher Microsoft Excel Worksheet Functions 8 15th Jan 2008 08:59 PM
Macro to convert a number to text (English only) John Google Microsoft Excel Discussion 4 18th Nov 2007 11:08 PM
Convert a number formatted as text to a number in a macro MACRE0 Microsoft Excel Programming 2 22nd Oct 2005 03:51 AM
convert text-format number to number in excel 2000%3f =?Utf-8?B?TGFycnk=?= Microsoft Excel Misc 1 29th Jul 2005 09:18 PM
Excel: Convert Number (1) to Text (one) alexg Microsoft Excel Misc 7 11th Oct 2003 10:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:20 AM.