ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   sumproduct or sumif in vba (https://www.excelbanter.com/excel-programming/346377-sumproduct-sumif-vba.html)

hellZg8

sumproduct or sumif in vba
 
I'm taking a long shot here but my question is
can sumproduct or sumif be used in VBA with a User filling in the blanks
with selections or text he/she has entered?

barry

sumproduct or sumif in vba
 
Hi

If you mean you want to use the SumIf function in VBA then yes you can. One
way is with the Evaluate function which will also allow you to build the
string from variables your user can set. Example would be:

strCriteriaRange = "Sheet1!A1:A10"
strCriteriaValue = "a"
strSumRange = "Sheet1!B1:B10"


MsgBox Evaluate("sumif(" & strCriteriaRange & ",""" & strCriteriaValue &
"""," & strSumRange & ")")

This will return the same value as if you put
=SumIf(Sheet1!A1:A10,"a",Sheet1!B1:B10) into a cell in the spreadsheet.

HTH

Barry


"hellZg8" wrote:

I'm taking a long shot here but my question is
can sumproduct or sumif be used in VBA with a User filling in the blanks
with selections or text he/she has entered?



All times are GMT +1. The time now is 04:34 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com