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: 49
Default variant array with formula strings to range formulae

Hello,

I inherited an Excel monster with lots of stale code, recorded macros,
goto-statements (!), you know what I mean. A tumor that has grown and
festered over many years.

So far I've been able to clean up a lot, and speed it up at the same
time. But there is one thing where I get stuck.

Let's say column A contains the following strings:
£='[##]worksheet_name'!$E$4
£='[##]worksheet_name'!$E$5
£='[##]worksheet_name'!$E$6
£='[##]worksheet_name'!$E$7
...
Actually, these are not hardcoded strings but values of an =INDIRECT()
formula. Don't ask, yer head will asplode. :-)

B, C and D are blank except for the first row, which contains the name
of other .xls files, who are always in the same directory as the main
file. Column A functions as a template for columns B, C and D.

The VBA code has to generate the formulae for B, C and D. How did they
do that?

1. copy column A4:A200 to B4:B200 (range(A).select, selection.copy,
range(B).select, selection.paste)
2. in column B, search & destroy^Wreplace every occurence of [##] with
[fileB.xls] (using the replace method on the range object). fileB.xls
is in the top row of column B.
3. in column B, search & replace every occurence of £= with = (again
using the replace method on the range object)
Repeat for column C and D.

3. is actually quite clever, because before the pasted text was just
text, but by removing the £ at the front of the text, Excel evaluates
it as a function.
But in 2. something goes wrong when I changed it from the short
filename to the full filename with ActiveWorkbook.Path: part of the
filename was repeated inside the formula. Looked really buggy...

My fix was to read in column A from range to variant array, loop
trough the array, make the text replacements in the formula template
string, and set the cell.Formula for each individual cell in column B.
My workaround works 100% correct, I'm confident about that. But...
sloooow. Of course, I have to iterate trough every cell in column B to
set the formula. If it were just a value that I had to write, it would
be a simple matter of saying colB=varArray. Bada bing, bada boom! No
such luck.

I have done some research, but I didn't find a way to set the formulae
of an entire range from an array. It seems like it can only be done
with values. Is that true?

Worst case scenario would be that I would have to restore the copy/
paste code and try to fix it, not rewrite it... :(

--
Amedee
 
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
Application.Match on an range defined to a variant array Keith R[_2_] Excel Programming 5 November 12th 07 10:37 PM
for each in range gives variant array mcgurkle Excel Programming 2 November 7th 07 03:17 PM
Write from variant array into range Bharath Rajamani Excel Programming 1 May 9th 07 11:24 AM
HowTo:Validation Formula = Array of strings AMDRIT Excel Programming 0 March 23rd 06 08:55 PM
Best way to paste a variant array into a range? AnneB Excel Programming 2 April 28th 04 09:57 PM


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