LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Writing to a range of cells

Please see this example code:

Public Function helloworld()
Dim hello(3) As Variant
hello(0) = 24
hello(1) = 33
hello(2) = 1
Me.Range("A1,B4,C5").Name = "YAY"
Me.Range("YAY") = hello
End Function

When you run this code, cells A1, B4, and C5 will all be set to the value 24.

Is it possible to write a variant out to a non-linear range of cells in this
fashion and have it so that A1 = 24, B4 = 33, and C5 = 1?

What's the purpose of me trying to do this? From Access I am trying to
automate a report which writes out to a range of cells.

The report right now takes several minutes (~30 at month end) to write
because I am writing it cell by cell. This seems trivial, but try doing this
with about 5000 lines of data, and about 50 value cells and 60 formula cells
per row. It bumps up the time to run the report to roughly 30 minutes,
because each time you make a call to excel to write out a cell it
significantly increases the time to write the report. That's got something
to do with overhead whenever you make a call to OLE Automation I assume, but
I'm not 100% sure if that's a correct statement.

What I would like to do, is copy the formulas and formats from a "template"
row (I do this already and it speeds up the execution somewhat to about 5-10
minutes faster than before), and then write out just the values at one time
per row as a variant array. This I know would speed up execution heavily.
To test this theory, I tried reformatting the report to have all of the
values in a linear range and write at one time (i.e.
excelSheet.Range("A1:A50").Value = myValuesArray) and it sped up execution to
run the whole report in about 5 minutes. Unfortunately, the folks seeing
this report would likely have a raging fit if they saw it like this (go
figure). They want this report in their specific format (gag...), which
means that I would have to use a non-linear range of columns per row to write
out the values. If anyone knows a solution, please let me know.
 
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
Need help writing Excel macro when range changes AT Excel Worksheet Functions 1 December 13th 07 03:09 AM
Writing a range to an array... Alex Excel Programming 2 December 29th 05 01:59 PM
writing range contents to arrays; best way? Matthew Dodds Excel Programming 1 January 5th 05 04:34 PM
Writing Range to Array Marston Excel Programming 3 August 9th 04 09:11 PM


All times are GMT +1. The time now is 12:30 PM.

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"