Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 115
Default Alternatives to VBA in Excel

Thomas -

Even with screen updating disabled, selecting cells and especially
activating worksheets can slow down the code.

Another big time waster is looping through a worksheet range and adding
cells to a VBA array one by one, then looping through the array to
repopulate the worksheet. Much better is to move the range into a VBA
variant in one step, and move the array back in another step:

dim vArray as Variant
vArray = Worksheets(1).Range("A1:D10").Value

now you can refer to vArray as if it were dimensioned (1 to 10, 1 to 4).
When you are done manipulating the array, or if by now it's in a
different array, you assign the range values to the array:

iRow = ubound(MyArray,1)+1-lbound(MyArray,1)
iCol = ubound(MyArray,2)+1-lbound(MyArray,2)
Worksheets(2).Range("A1").resize(iRow,jCol).value = MyArray

When I first learned this trick on an old 486 machine, it was amazing
how much more quickly it worked. On these newer GHz machines, it's less
of a difference, but still noticeable.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______

Thomas Kregeloh wrote:

Hi Bob,
is this also true when screen updating is switched off?
Thomas


"Bob Phillips" schrieb im Newsbeitrag
...

The problem with select is that it is slow, and if there is a lot of it
going on, it can make quite a performance difference. If on top of that


you

move between worksheets, that compounds the problem. For instance, this is
the sort of code that the macro recorder creates

Range("A1").Select
Selection.Value = "abc"

can be more efficiently written as

Range("A1").Value = "abc"

The amount of work removed here, and the CPU cycles, is significant, but


the

result is exactly the same.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)





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
Alternatives for Excel when too few rows Jesper Excel Discussion (Misc queries) 6 April 2nd 08 11:03 PM
Alternatives for Excel for charting dated time-series? Matthew Pollock Charts and Charting in Excel 2 March 7th 05 01:20 PM
Alternatives to Excel Spider Excel Discussion (Misc queries) 2 March 1st 05 01:03 PM
Pocket Excel Alternatives? MB7 Excel Discussion (Misc queries) 0 February 16th 05 04:03 PM
OLDEDB alternatives for pulling data from Excel Glenn Thimmes Excel Programming 0 April 14th 04 03:37 PM


All times are GMT +1. The time now is 09:30 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"