Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Programming Array Formulas in VBA - Can they be intermediate results in RAM?

I'd like to be able to set a cell value, using the results of an array
formula as an intermediate step. For example, Column 1 of my data is a
timestamp. Column 5 is series of numbers. I want to place, on sheet 2,
the maximum value of column 5, and the date/time that it occurred.

I've actually got many columns to perform this on, and each column has
a named range that covers the column just from row 2 to the last row
with data. In the example below, I'm interested in the range
InBytesCur

The following from John Walkenbach's 2003 formula book suggests this
array formula for finding the row of the max
=MIN(IF(InBytesCur=MAX(InBytesCur),ROW(InBytesCur) , ""))

1) If I use this code to get the row of the max:
Dim TC As Range
Set TC = Range("Sheet2!a2")
TC.FormulaArray =
"=MIN(IF(InBytesCur=MAX(InBytesCur),ROW(InBytesCur ), ""))"

I get the error that it can't set the FormulaArray property on the
range object. I'm getting that error a lot, trying to learn to program
array formulas into my worksheets via macros. I've discovered the
messages in this group that explain VBA won't accept an FormulaArray
string of more than 256 chars, but that doesn't explain why the above
example won't run.

But in the larger picture, I'd prefer to figure out how to use the
Array Formula directly, without having to place it's results in a
cell. Can an Array Formula operate in memory, without having to place
it's results in a cell? If so, I can find the date/time value I need
using RC offset on the data sheet (Row X, Column 1, where X comes from
the Array Formula).

Thanks in advance for any pointers!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Programming Array Formulas in VBA - Can they be intermediate results in RAM?

You nearly got it - just a bit of trouble with the quote marks.
Instead of "", try """"


As for the larger picture, something like this might work:

Sub test()
Dim rng As Range

Set rng = Range("InBytesCur")
With WorksheetFunction
Set rng = rng(.Match(.Max(rng), rng, 0))
End With

MsgBox rng.Address & " = " & rng.Value
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Bill Hertzing" wrote in message
m...
I'd like to be able to set a cell value, using the results of an array
formula as an intermediate step. For example, Column 1 of my data is a
timestamp. Column 5 is series of numbers. I want to place, on sheet 2,
the maximum value of column 5, and the date/time that it occurred.

I've actually got many columns to perform this on, and each column has
a named range that covers the column just from row 2 to the last row
with data. In the example below, I'm interested in the range
InBytesCur

The following from John Walkenbach's 2003 formula book suggests this
array formula for finding the row of the max
=MIN(IF(InBytesCur=MAX(InBytesCur),ROW(InBytesCur) , ""))

1) If I use this code to get the row of the max:
Dim TC As Range
Set TC = Range("Sheet2!a2")
TC.FormulaArray =
"=MIN(IF(InBytesCur=MAX(InBytesCur),ROW(InBytesCur ), ""))"

I get the error that it can't set the FormulaArray property on the
range object. I'm getting that error a lot, trying to learn to program
array formulas into my worksheets via macros. I've discovered the
messages in this group that explain VBA won't accept an FormulaArray
string of more than 256 chars, but that doesn't explain why the above
example won't run.

But in the larger picture, I'd prefer to figure out how to use the
Array Formula directly, without having to place it's results in a
cell. Can an Array Formula operate in memory, without having to place
it's results in a cell? If so, I can find the date/time value I need
using RC offset on the data sheet (Row X, Column 1, where X comes from
the Array Formula).

Thanks in advance for any pointers!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Programming Array Formulas in VBA - Can they be intermediate results in RAM?

Bill,

One way of getting the result in VBA is as Rob shows, but with nested
functions this can get messy. Here is an alternative using your formula

myResult = Evaluate("=MIN(IF(InBytesCur=MAX(InBytesCur),ROW(I nBytesCur),
""""))")

--

HTH

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

"Bill Hertzing" wrote in message
m...
I'd like to be able to set a cell value, using the results of an array
formula as an intermediate step. For example, Column 1 of my data is a
timestamp. Column 5 is series of numbers. I want to place, on sheet 2,
the maximum value of column 5, and the date/time that it occurred.

I've actually got many columns to perform this on, and each column has
a named range that covers the column just from row 2 to the last row
with data. In the example below, I'm interested in the range
InBytesCur

The following from John Walkenbach's 2003 formula book suggests this
array formula for finding the row of the max
=MIN(IF(InBytesCur=MAX(InBytesCur),ROW(InBytesCur) , ""))

1) If I use this code to get the row of the max:
Dim TC As Range
Set TC = Range("Sheet2!a2")
TC.FormulaArray =
"=MIN(IF(InBytesCur=MAX(InBytesCur),ROW(InBytesCur ), ""))"

I get the error that it can't set the FormulaArray property on the
range object. I'm getting that error a lot, trying to learn to program
array formulas into my worksheets via macros. I've discovered the
messages in this group that explain VBA won't accept an FormulaArray
string of more than 256 chars, but that doesn't explain why the above
example won't run.

But in the larger picture, I'd prefer to figure out how to use the
Array Formula directly, without having to place it's results in a
cell. Can an Array Formula operate in memory, without having to place
it's results in a cell? If so, I can find the date/time value I need
using RC offset on the data sheet (Row X, Column 1, where X comes from
the Array Formula).

Thanks in advance for any pointers!



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Programming Array Formulas in VBA - Can they be intermediate results in RAM?

The second argument is superfluous (without this, it returns false which
works fine)

=MIN(IF(InBytesCur=MAX(InBytesCur),ROW(InBytesCur) ))

Should work fine and eliminates the double quote problem.

Dim TC As Range
Set TC = Range("Sheet2!a2")
TC.FormulaArray = _
"=MIN(IF(InBytesCur=MAX(InBytesCur),ROW(InBytesCur )))"

or

res = Evaluate("MIN(IF(InBytesCur=MAX(InBytesCur),ROW(In BytesCur)))")

But Rob has shown you how to get the row without using an array formula
either in the worksheet or in code.

--
Regards,
Tom Ogilvy


"Bill Hertzing" wrote in message
m...
I'd like to be able to set a cell value, using the results of an array
formula as an intermediate step. For example, Column 1 of my data is a
timestamp. Column 5 is series of numbers. I want to place, on sheet 2,
the maximum value of column 5, and the date/time that it occurred.

I've actually got many columns to perform this on, and each column has
a named range that covers the column just from row 2 to the last row
with data. In the example below, I'm interested in the range
InBytesCur

The following from John Walkenbach's 2003 formula book suggests this
array formula for finding the row of the max
=MIN(IF(InBytesCur=MAX(InBytesCur),ROW(InBytesCur) , ""))

1) If I use this code to get the row of the max:
Dim TC As Range
Set TC = Range("Sheet2!a2")
TC.FormulaArray =
"=MIN(IF(InBytesCur=MAX(InBytesCur),ROW(InBytesCur ), ""))"

I get the error that it can't set the FormulaArray property on the
range object. I'm getting that error a lot, trying to learn to program
array formulas into my worksheets via macros. I've discovered the
messages in this group that explain VBA won't accept an FormulaArray
string of more than 256 chars, but that doesn't explain why the above
example won't run.

But in the larger picture, I'd prefer to figure out how to use the
Array Formula directly, without having to place it's results in a
cell. Can an Array Formula operate in memory, without having to place
it's results in a cell? If so, I can find the date/time value I need
using RC offset on the data sheet (Row X, Column 1, where X comes from
the Array Formula).

Thanks in advance for any pointers!



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Programming Array Formulas in VBA - Can they be intermediate results in RAM?

Thank you all for your excellent suggestions!


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
E2007 formulas display as formulas, not results Pierre Excel Worksheet Functions 3 January 14th 10 04:59 PM
Intermediate value of a set of array. HARSHAWARDHAN. S .SHASTRI[_2_] Excel Worksheet Functions 5 September 25th 08 09:01 PM
Using intermediate results in Worksheet functions [email protected] Excel Worksheet Functions 6 February 6th 08 02:59 AM
Exclude 0 from MIN array results Craig Excel Discussion (Misc queries) 2 January 11th 07 05:26 PM
Array formulas into VB programming Angelo Battistoni Excel Programming 3 August 28th 03 05:34 PM


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