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

In my VBA code I use:
....
For Each c In Range("MyRange").Cells
c.Value = CSng(c.Value)
Next c
....
and it is performance bootleneck of that code

Can you, please, suggest better code.
Thank you in advance!

Vlado
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default convert text to number - performance problem

Vlado,
What are you trying to accomplish?
Numeric values in cells are always type Double.
--
Jim Cone
Portland, Oregon USA



"Vladimir Sveda"
<Vladimir

wrote in message
In my VBA code I use:
....
For Each c In Range("MyRange").Cells
c.Value = CSng(c.Value)
Next c
....
and it is performance bootleneck of that code
Can you, please, suggest better code.
Thank you in advance!
Vlado
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default convert text to number - performance problem

Hi Vladimir, can you paste the full code (or atleast the code above For
Each). Also usually range is specified as below

Dim MyRange As Range
Set MyRange = Range("A1:A10")
For Each c In MyRange.Cells
c.Value = CSng(c.Value)
Next c

If this post helps click Yes
---------------
Jacob Skaria


"Vladimir Sveda" wrote:

In my VBA code I use:
...
For Each c In Range("MyRange").Cells
c.Value = CSng(c.Value)
Next c
...
and it is performance bootleneck of that code

Can you, please, suggest better code.
Thank you in advance!

Vlado

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default convert text to number - performance problem

Hi Vladimir, if the problem is the time it takes to loop through the range
and convert the individual values, then it might be better to just convert
only when they are used. That is, if a value from that range is needed for a
calculation or some other use, then use the CSng(value) at that time.
Otherwise, I believe you are stuck with doing the loop.

"Vladimir Sveda" wrote:

In my VBA code I use:
...
For Each c In Range("MyRange").Cells
c.Value = CSng(c.Value)
Next c
...
and it is performance bootleneck of that code

Can you, please, suggest better code.
Thank you in advance!

Vlado

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 968
Default convert text to number - performance problem

Dim vArr as variant
dim j as long
dim k as long

varr=Range("MyRange").Value2

on error resume next
for j=lbound(varr,1) to ubound(varr,1)
for k=lbound(varr,2) to ubound(varr,2)
varr(j,k)=cdbl(varr(j,k))
next k
next j
Range("MyRange")=varr

"Vladimir Sveda" <Vladimir wrote in message
...
In my VBA code I use:
...
For Each c In Range("MyRange").Cells
c.Value = CSng(c.Value)
Next c
...
and it is performance bootleneck of that code

Can you, please, suggest better code.
Thank you in advance!

Vlado





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default convert text to number - performance problem

Thanks to all, solved by "philosophy change" (and of course algorithm change)

Vlado

"Vladimir Sveda" wrote:

In my VBA code I use:
...
For Each c In Range("MyRange").Cells
c.Value = CSng(c.Value)
Next c
...
and it is performance bootleneck of that code

Can you, please, suggest better code.
Thank you in advance!

Vlado

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 to number problem Rob Excel Discussion (Misc queries) 10 March 16th 07 12:24 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


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