LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Michael
 
Posts: n/a
Default Using a range variable inside a excel function

Hey guys.

I am writing a script to go through an excel file and examine/analysize the
data. I have the script working when I hard code in the range, but I need to
make it more modular so that I do not have to change it every time the size
of the sheets change.

Here is what I have:

Sheets("SUM").cells(n,j) = Evaluate("=SUMPRODUCT(($C$2:$C$670=""" & empName
& """) * ($E$2:$E$670=""" & tempMonth & """)*($D$2:$D$670))")

This is what I want it to be like:

Dim myNameRange As Range
Dim myHourRange As Range
Dim myMonthRange As Range

Dim tempLastRow
tempLastRow = Sheets("TEMP").Cells(Rows.Count, "A").End(xlUp).Row

Set myNameRange = Range(Cells(2, 3), Cells(tempLastRow, 3))
Set myHourRange = Range(Cells(2, 4), Cells(tempLastRow, 4))
Set myMonthRange = Range(Cells(2, 5), Cells(tempLastRow, 5))

Sheets("SUM").cells(n,j) = Evaluate("=SUMPRODUCT((myNameRange=""" & empName
& """) * (myMonthRange=""" & tempMonth & """)*(myHourRange))")

I cannot make this work. How do I make the excel function recognize the
ranges?

I greatly appreciate any assistance you could provide.

Thanks,

-Michael
 
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
creating function (vba) with range arguments Fredouille Excel Worksheet Functions 2 September 12th 05 11:01 AM
Help PLEASE! Not sure what answer is: Match? Index? Other? baz Excel Worksheet Functions 7 September 3rd 05 03:47 PM
@ and "function not valid" error (Excel 2003) Acert93 New Users to Excel 1 September 2nd 05 07:17 AM
A function to get a variable row reference for range in XNPV funct Tex1960 Excel Worksheet Functions 6 August 1st 05 11:20 PM
Excel should have a quick and simple "change case" function like . NinaSvendsen Excel Worksheet Functions 1 January 28th 05 03:15 PM


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