Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Trying to Mimic an Array Function in VBA

Hello,

I've been trying to create a VBA function that emulates one of my favorite
array functions. The function summarizes a data set for all rows where the
first item in the row matches a supplied value and all columns where the
first item in the column matches another supplied value.

I can create a loop that cylces through the data set summarizing the data I
am seeking, but such an approach is very slow. Accordingly, I've been
seeking a faster solution and have turned to the EVALUATE method to mimic an
array function.

Here's what's I've got so far:

Function TableSum(RowValue, ColumnValue, Ref As Range)
RefText = Ref.Address(external:=True)
RowText = RowValue.Address(external:=True)
ColText = ColumnValue.Address(external:=True)
TableSum = Evaluate("SUM((INDEX(" & RefText & ",0,1)=" & RowText &
")*(INDEX(" & RefText & ",1,0)=" & ColText & ")*IF(ISNUMBER(" & RefText &
")," & RefText & ",0))")
End Function

The funciton works perfectly SO LONG AS all the inputs are from the calling
worksheet. Once I reference ranges on other worksheets, the function does
not work.

Any thoughts? Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Trying to Mimic an Array Function in VBA


Function TableSum(RowValue, ColumnValue, Ref As Range)
TableSum = 0
for RowCount = 2 to Ref.Rows.Count
if Ref(RowCount,1).Value = RowValue then
for ColCount = 2 to Ref.Columns.Count
if Ref(1,ColCount).Value = ColumnValue then
TableSum = TableSum + Ref(RowCount,ColCount).Value
end if
next ColCount
end if
Next RowCount
end Sub


end function

"Brian Cass" wrote:

Hello,

I've been trying to create a VBA function that emulates one of my favorite
array functions. The function summarizes a data set for all rows where the
first item in the row matches a supplied value and all columns where the
first item in the column matches another supplied value.

I can create a loop that cylces through the data set summarizing the data I
am seeking, but such an approach is very slow. Accordingly, I've been
seeking a faster solution and have turned to the EVALUATE method to mimic an
array function.

Here's what's I've got so far:

Function TableSum(RowValue, ColumnValue, Ref As Range)
RefText = Ref.Address(external:=True)
RowText = RowValue.Address(external:=True)
ColText = ColumnValue.Address(external:=True)
TableSum = Evaluate("SUM((INDEX(" & RefText & ",0,1)=" & RowText &
")*(INDEX(" & RefText & ",1,0)=" & ColText & ")*IF(ISNUMBER(" & RefText &
")," & RefText & ",0))")
End Function

The funciton works perfectly SO LONG AS all the inputs are from the calling
worksheet. Once I reference ranges on other worksheets, the function does
not work.

Any thoughts? Thanks

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
Mimic a watermark BusAdmAsst Excel Discussion (Misc queries) 2 April 11th 07 12:16 AM
Mimic keystrokes? Targus Excel Programming 1 March 8th 06 05:09 PM
mimic goalseek Monique Excel Programming 6 August 25th 05 07:11 PM
Code to mimic vlookup Mark Excel Programming 0 March 29th 05 07:21 PM
Mimic Undo actions Chris W. Excel Programming 2 March 21st 05 03:00 PM


All times are GMT +1. The time now is 09:55 PM.

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

About Us

"It's about Microsoft Excel"