PC Review


Reply
Thread Tools Rate Thread

convert text to number - performance problem

 
 
Vladimir Sveda
Guest
Posts: n/a
 
      25th Mar 2009
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 With Quote
 
 
 
 
Jim Cone
Guest
Posts: n/a
 
      25th Mar 2009
Vlado,
What are you trying to accomplish?
Numeric values in cells are always type Double.
--
Jim Cone
Portland, Oregon USA



"Vladimir Sveda"
<Vladimir
(E-Mail Removed)>
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
 
Reply With Quote
 
Jacob Skaria
Guest
Posts: n/a
 
      25th Mar 2009
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

 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      25th Mar 2009
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

 
Reply With Quote
 
Charles Williams
Guest
Posts: n/a
 
      25th Mar 2009
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 (E-Mail Removed)> wrote in message
news:958CCA97-F416-4A34-B41A-(E-Mail Removed)...
> 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 With Quote
 
Vladimir Sveda
Guest
Posts: n/a
 
      25th Mar 2009
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 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 number to number formate thisis_anwar@hotmail.com Microsoft Excel Misc 2 9th Apr 2007 10:48 AM
Convert a number formatted as text to a number in a macro MACRE0 Microsoft Excel Programming 2 22nd Oct 2005 02:51 AM
convert text-format number to number in excel 2000%3f =?Utf-8?B?TGFycnk=?= Microsoft Excel Misc 1 29th Jul 2005 08:18 PM
not able to convert text, or graphic number to regular number in e =?Utf-8?B?a251dHNlbms=?= Microsoft Excel Worksheet Functions 1 2nd Apr 2005 08:41 AM
Convert number in text format to number =?Utf-8?B?Q2hlcnls?= Microsoft Excel Programming 2 25th May 2004 06:51 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:19 AM.