Click here to Skip to main content
15,896,522 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

This is my second attempt seeking help, im quite new to programming however I did manage to write a neat program on excel for my workmates which deals with reports.

Currently I need a VBA format formula that calculates a CountIf statement with 2 different columns.
#Note this is pulled from a different sheet in the same workbook.
Column 1 = Name<br />
Column 3 = Date, DateFormat = "24/10/2011"


Heres the following code that I tried to compile.

Try 1
VB
Dim Name As String
Dim Date1 As Double
Dim iRequestTest As String

Name = Worksheets("UK-Oracle-Financials").Range("D29").Value
Date1 = Worksheets("Requests").Range("H12781").Value

iRequestTest = Application.SumProduct((Sheets("Requests").Range("H1:H65535") = " & Date1 & ") * (Sheets(Requests).Range("C1:C65535") = """ & Name & """))

Application.Evaluate (iRequestTest )
Worksheets("UK-Oracle-Financials").Range("L23").Value = iRequestTest


Try 2
VB
iRequestTest = Evaluate("=SUMPRODUCT(--(Requests!H1:H65535<=dateMarch2012End), (Requests!H1:H65535>=date*(Requests!D1:D65535="Marcus Comins")))]


Try 3
VB
RequestsTest = iRequestsTest + Application.WroksheetFunction.SumProduct(--Sheets("Incidents").Range("F1:F65535") <= date1) * Application.WorksheetFunction.CountIf(Sheets("Requests").Range("C:C"), "Marcus Comins")


For some reason I cant translate the following formula into DB.. If i Could then it would be great.
=SUMPRODUCT(--(Requests!H1:H65535<=DATE(2012,4,31))*(Requests!D1:D65535="Marcus Comins"))

I would appreciate any tips or suggestions to improve my tecnique.

Thank you.


My next step would be to allocate a new variable to Date1 with a case or condition based on the parameter selections from the combo box by the user. So if April is selected the Date1 variable will change and point its value somewhere else and etc.. Think this will minimise the complexity of the code.

Suggestions?

[EDIT]"Code" tags and text from comment added - LOSMAC[/EDIT]
Posted
Updated 19-Apr-12 5:10am
v3
Comments
ArmCorp 19-Apr-12 9:53am    
My next step would be to allocate a new variable to Date1 with a case or condition based on the parameter selections from the combo box by the user.
So if April is selected the Date1 variable will change and point its value somewhere else and etc.. Think this will minimise the complexity of the code.

Suggestions?
Maciej Los 19-Apr-12 11:10am    
Use "Improve question" button to improve your question ;)

First of all, read this article: WorksheetFunction.SumProduct Method (Excel)[^]
The most important is that the returned value is double, not string. Date must be a date, not double.

Here you'll find an answer:
http://www.mrexcel.com/forum/showthread.php?t=73471[^]
http://www.excelforum.com/excel-programming/481698-solved-sumproduct-in-vba.html[^]
 
Share this answer
 
Still doesnt work ive tried changing the formula around and requestsTest returns a double and teh date returns a date however its still the same.
I can't get the symantics right at this point.. Any advice?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900