Using Variables in VBA Function

millhouse123

Active Member
Joined
Aug 22, 2006
Messages
334
Last week I got help writing this SUMPRODUCT funtion with constants as the comparison but I now want to put variables in their place. I have a feeling my problem has to do with the quotes but no matter what I try I can't get it to work Perhaps somone can give me an idea. Below is the code.
The REPT_TYPE and ACCTNUM variables I am having trouble with.

Thanks

This is just the applicable code....

Sub Joe()


Worksheets("RESULTS").Activate ' Setup second worksheet to received calculated results
Range("A2").Activate ' Set initial cell to dump data
ACCTNUM = ActiveCell.Value

Do Until ActiveCell.Value = "" ' Keep going until last account has been processed.

Worksheets("DATA").Activate ' This statement required for next one to run properly
FINROW = Range("A65536").End(xlUp).Row

CELLRANGE = "$A$2:" & "$A" & "$" & FINROW: Range(CELLRANGE).Name = "ACCT_NUMB_RANGE"
CELLRANGE = "$P$2:" & "$P" & "$" & FINROW: Range(CELLRANGE).Name = "REPT_TYPE_RANGE"
CELLRANGE = "$J$2:" & "$J" & "$" & FINROW: Range(CELLRANGE).Name = "MKT_VAL_RANGE"

Dim REPT_TYPE_Name(1 To 5) As String
Dim DATA_VALUE(1 To 30) As Long
Dim CALCRESULT As Variant
REPT_TYPE_Name(1) = "Cash Equivalents"
REPT_TYPE_Name(2) = "Fixed"
REPT_TYPE_Name(3) = "Equity"
REPT_TYPE_Name(4) = "Other"


For REPT_TYPE = 1 To 4

CALCRESULT = Evaluate("=sumproduct(--(" & ACCT_NUMB_RANGE.Address & " = ""ACCTNUM""), --(" & REPT_TYPE_RANGE.Address & " = ""REPT_TYPE_Name(REPT_TYPE[/b])""), " & MKT_VAL_RANGE.Address & ")")

Next REPT_TYPE

MsgBox REPT_TYPE_Name(1)

Loop

End Sub[/code]
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
Hi,

what do you expect this code to do ?
it would be better you refered to the original code
is it the EVALUATE-line which doens't work ?

can't you continue in the original thread ?
you could PM Joe Was (isn't he the author ?)

kind regards,
Erik
 

Forum statistics

Threads
1,141,734
Messages
5,708,157
Members
421,549
Latest member
Dtcfire

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top