Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Changing text to number format using type casting


Hi,

I have made a macro that copies data from a number of sheets into
main one. One of the columns in the main sheet contains numbers to b
used in a vlookup. The problem is that when some of the numbers ar
copied across to the main sheet they remain in text format, as the
were stored in this format on the source sheet.

Once all the copying is done I need to make sure that all numbers in
certain column are stored as numbers. I tried the following, howeve
the line,
MyCell.Value = CInt(MyCell.Value) caused an error. Is this the way t
do this, i.e type casting, and if so why does this not work. Or i
there a better way, maybe something that works on the whole range a
opposed to each cell individually?

Set MyCell = ActiveSheet.Range("C2")
Do While MyCell.Value < ""
MyCell.Value = CInt(MyCell.Value)
Set MyCell = MyCell.Offset(1, 0)
Loop

Cheers,

To

--
Tomsk
-----------------------------------------------------------------------
Tomski's Profile: http://www.excelforum.com/member.php...fo&userid=2682
View this thread: http://www.excelforum.com/showthread.php?threadid=50253

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Changing text to number format using type casting

Tom,
Try:

MyCell.Value = CLng(DateValue(MyCell.Value))

"Tomski" wrote:


Hi,

I have made a macro that copies data from a number of sheets into a
main one. One of the columns in the main sheet contains numbers to be
used in a vlookup. The problem is that when some of the numbers are
copied across to the main sheet they remain in text format, as they
were stored in this format on the source sheet.

Once all the copying is done I need to make sure that all numbers in a
certain column are stored as numbers. I tried the following, however
the line,
MyCell.Value = CInt(MyCell.Value) caused an error. Is this the way to
do this, i.e type casting, and if so why does this not work. Or is
there a better way, maybe something that works on the whole range as
opposed to each cell individually?

Set MyCell = ActiveSheet.Range("C2")
Do While MyCell.Value < ""
MyCell.Value = CInt(MyCell.Value)
Set MyCell = MyCell.Offset(1, 0)
Loop

Cheers,

Tom


--
Tomski
------------------------------------------------------------------------
Tomski's Profile: http://www.excelforum.com/member.php...o&userid=26824
View this thread: http://www.excelforum.com/showthread...hreadid=502530


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default Changing text to number format using type casting

Hi Tomski

Insted of copy you can "copy" like this:

'wher you copy from
Dim n As Double
n = Val(Sheets("Ark2").Range("A1"))
'wher you copy to
Sheets("Ark1").Range("A1").NumberFormat = "General"
Sheets("Ark1").Range("A1") = n

Regards Yngve

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Changing text to number format using type casting


Excellent, that NumberFormat property of a range works a treat, cheers.

It would be good if there was a list of object properties somewhere as
there are so many that are so useful.

Cheers,

Tom


--
Tomski
------------------------------------------------------------------------
Tomski's Profile: http://www.excelforum.com/member.php...o&userid=26824
View this thread: http://www.excelforum.com/showthread...hreadid=502530

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
Nested If statement to control format of number-type cells TB Excel Worksheet Functions 3 May 16th 08 01:35 AM
Text Import Wizard - Changing number format Thad Meyers[_2_] Excel Discussion (Misc queries) 0 August 13th 07 09:42 PM
Adding new 'Type' to Format->Number->Time->Type Chip Pearson Excel Discussion (Misc queries) 5 September 26th 05 08:45 PM
Changing format of number without changing the value sweetsue516 Excel Discussion (Misc queries) 2 August 22nd 05 04:07 PM
Changing a specific character type in text string olasa Excel Discussion (Misc queries) 0 March 20th 05 11:35 PM


All times are GMT +1. The time now is 01:07 PM.

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"