Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Trying to convert text to number

I'm trying to convert all numbers in Column H from text to number. Some
numbers are text (with an apostrophe at the beginning) and some are just
plain number.
If I put a 1 in an empty cell and manual do a Copy/Paste Special/Multiply,
it works.

This is what I wrote:
Sub ConvertPINtoNum()
Range("H2").Select
RowCount = 2
Do While Range("F" & (RowCount)) < ""
Range("H" & (RowCount)) = ("H" & (RowCount)) * 1
RowCount = RowCount + 1
Loop
End Sub

I'm getting a type mismatch error on the line
Range("H" & (RowCount)) = ("H" & (RowCount)) * 1
I also tried
but I'm getting a type mismatch error on the line
Range("H" & (RowCount)) = ("H" & (RowCount)) * 1
but that gave me the type mismatch error as well.

Any help very much appreciated.

Thanks,
Dee


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Trying to convert text to number

Syntax error....Try the below

Sub ConvertPINtoNum()
RowCount = 2
Do While Range("F" & RowCount) < ""
Range("H" & RowCount) = Range("H" & RowCount) * 1
RowCount = RowCount + 1
Loop
End Sub


--
Jacob


"Dee Sperling" wrote:

I'm trying to convert all numbers in Column H from text to number. Some
numbers are text (with an apostrophe at the beginning) and some are just
plain number.
If I put a 1 in an empty cell and manual do a Copy/Paste Special/Multiply,
it works.

This is what I wrote:
Sub ConvertPINtoNum()
Range("H2").Select
RowCount = 2
Do While Range("F" & (RowCount)) < ""
Range("H" & (RowCount)) = ("H" & (RowCount)) * 1
RowCount = RowCount + 1
Loop
End Sub

I'm getting a type mismatch error on the line
Range("H" & (RowCount)) = ("H" & (RowCount)) * 1
I also tried
but I'm getting a type mismatch error on the line
Range("H" & (RowCount)) = ("H" & (RowCount)) * 1
but that gave me the type mismatch error as well.

Any help very much appreciated.

Thanks,
Dee


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Trying to convert text to number

Try the below alternate method. You dont need to loop...

Columns("H") = Columns("H").value

--
Jacob


"Dee Sperling" wrote:

I'm trying to convert all numbers in Column H from text to number. Some
numbers are text (with an apostrophe at the beginning) and some are just
plain number.
If I put a 1 in an empty cell and manual do a Copy/Paste Special/Multiply,
it works.

This is what I wrote:
Sub ConvertPINtoNum()
Range("H2").Select
RowCount = 2
Do While Range("F" & (RowCount)) < ""
Range("H" & (RowCount)) = ("H" & (RowCount)) * 1
RowCount = RowCount + 1
Loop
End Sub

I'm getting a type mismatch error on the line
Range("H" & (RowCount)) = ("H" & (RowCount)) * 1
I also tried
but I'm getting a type mismatch error on the line
Range("H" & (RowCount)) = ("H" & (RowCount)) * 1
but that gave me the type mismatch error as well.

Any help very much appreciated.

Thanks,
Dee


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Trying to convert text to number

You might need to convert the cell format to "General" before your statement
to handle the cells currently formatted as Text...

Columns("H").NumberFormat = "General"
Columns("H").Value = Columns("H").Value

Note to Dee... The technique of assigning the Value property back onto
itself should only be used on cells containing constant value; if the cell
has a formula in it, that formula would be replaced by the value it is
displaying. You can get around that problem by assigning the Formula
property back onto itself instead...

Columns("H").NumberFormat = "General"
Columns("H").Formula= Columns("H").Formula

You can use this on both cells containing formulas and constants and only
the constants will be changed... the formulas will remain as formulas.

--
Rick (MVP - Excel)


"Jacob Skaria" wrote in message
...
Try the below alternate method. You dont need to loop...

Columns("H") = Columns("H").value

--
Jacob


"Dee Sperling" wrote:

I'm trying to convert all numbers in Column H from text to number. Some
numbers are text (with an apostrophe at the beginning) and some are just
plain number.
If I put a 1 in an empty cell and manual do a Copy/Paste
Special/Multiply,
it works.

This is what I wrote:
Sub ConvertPINtoNum()
Range("H2").Select
RowCount = 2
Do While Range("F" & (RowCount)) < ""
Range("H" & (RowCount)) = ("H" & (RowCount)) * 1
RowCount = RowCount + 1
Loop
End Sub

I'm getting a type mismatch error on the line
Range("H" & (RowCount)) = ("H" & (RowCount)) * 1
I also tried
but I'm getting a type mismatch error on the line
Range("H" & (RowCount)) = ("H" & (RowCount)) * 1
but that gave me the type mismatch error as well.

Any help very much appreciated.

Thanks,
Dee



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 a number formatted as text to a number in a macro MACRE0[_5_] Excel Programming 2 October 22nd 05 02:51 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
Convert number in text format to number Cheryl[_3_] Excel Programming 2 May 25th 04 06:51 PM


All times are GMT +1. The time now is 06:43 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"