GRCArizona
Board Regular
- Joined
- Apr 24, 2010
- Messages
- 95
Hi All -
I'm using a UF where a user can select from 1 to 5 Categories. I'm looking for a formula in VBA that uses a SUMIFS formula where the Category is dynamic. So, if a user selects only 1 category IE: Tires, the SUMIFS formula would be:
SUMIFS(F$5:F$5282,$C$5:$C$5282,"Tires",$D$5:$D$5282,$D5290
If the user selects "Tires" and "Battery", the formula would be:
SUMIFS(F$5:F$5282,$C$5:$C$5282,"Tires",$D$5:$D$5282,$D5290 + SUMIFS(F$5:F$5282,$C$5:$C$5282,"Battery",$D$5:$D$5282,$D5290.
Here is the code I'm using:
I've got the code working with the exception of the dynamic part. The formula returned is not putting quotes around Tires, so the formula is not summing up b/c the quotes are missing. If I add quotes to the VBA, then instead of returnign "Tires", I'm getting & IncludedList.Value &
Anybody know what I can use to ensure this works?
Thx
I'm using a UF where a user can select from 1 to 5 Categories. I'm looking for a formula in VBA that uses a SUMIFS formula where the Category is dynamic. So, if a user selects only 1 category IE: Tires, the SUMIFS formula would be:
SUMIFS(F$5:F$5282,$C$5:$C$5282,"Tires",$D$5:$D$5282,$D5290
If the user selects "Tires" and "Battery", the formula would be:
SUMIFS(F$5:F$5282,$C$5:$C$5282,"Tires",$D$5:$D$5282,$D5290 + SUMIFS(F$5:F$5282,$C$5:$C$5282,"Battery",$D$5:$D$5282,$D5290.
Here is the code I'm using:
Dim n as Integer
Dim Category as String
Category = "="
For n = 1 To IncludedList.ListCount
IncludedList.SetFocus
IncludedList.ListIndex = n - 1
Category = Category & "+" & "SUMIFS(F$5:F$5282,$C$5:$C$5282," & IncludedList.Value & ",$D$5:$D$5282,$D5290)"
Next
Dim Category as String
Category = "="
For n = 1 To IncludedList.ListCount
IncludedList.SetFocus
IncludedList.ListIndex = n - 1
Category = Category & "+" & "SUMIFS(F$5:F$5282,$C$5:$C$5282," & IncludedList.Value & ",$D$5:$D$5282,$D5290)"
Next
I've got the code working with the exception of the dynamic part. The formula returned is not putting quotes around Tires, so the formula is not summing up b/c the quotes are missing. If I add quotes to the VBA, then instead of returnign "Tires", I'm getting & IncludedList.Value &
Anybody know what I can use to ensure this works?
Thx