Hi guys, new ish to VBA so would appreciate some help on the syntax for this, can't seem to find what I'm looking for elsewhere.
I would like to create a sumifs and countif formula in VBA that calculates a sum of premium and count of policy number.
I would like to create a 'Summary' sheet that basically looks at another sheet which has my data and does a sumifs based on 2 criteria and a countif based on one criteria (so I'm referencing a different sheet to the sheet my formulas will be in). Below is the formula in Excel:
=SUMIFS('All Key Risks'!D:D,'All Key Risks'!I:I,A2&"*")
where the name of the sheet I'm referencing is 'All Key Risks' and taking the sum range of column D with the criteria range being in column I and the criteria being the value in cell A2 of active sheet and adding a wildcard character.
I'm struggling to get the syntax right in my VBA code. Currently I have the below where B2 is the cell I want the formula populated in the 'Summary' sheet.
Range("B2").Value = application.WorksheetFunction.SumIfs(worksheets(1).range("D:D"),worksheets(1).range("I:I"),A2&"*"))
The problem I have is the correct way to reference the sheet name in my formula. The reason is used 'Worksheets(1) is because the data I'm summing from will always be on Sheet 1 so I'm trying to reference the range D:D and I:I on that sheet.
Anyone have a solution?
I would like to create a sumifs and countif formula in VBA that calculates a sum of premium and count of policy number.
I would like to create a 'Summary' sheet that basically looks at another sheet which has my data and does a sumifs based on 2 criteria and a countif based on one criteria (so I'm referencing a different sheet to the sheet my formulas will be in). Below is the formula in Excel:
=SUMIFS('All Key Risks'!D:D,'All Key Risks'!I:I,A2&"*")
where the name of the sheet I'm referencing is 'All Key Risks' and taking the sum range of column D with the criteria range being in column I and the criteria being the value in cell A2 of active sheet and adding a wildcard character.
I'm struggling to get the syntax right in my VBA code. Currently I have the below where B2 is the cell I want the formula populated in the 'Summary' sheet.
Range("B2").Value = application.WorksheetFunction.SumIfs(worksheets(1).range("D:D"),worksheets(1).range("I:I"),A2&"*"))
The problem I have is the correct way to reference the sheet name in my formula. The reason is used 'Worksheets(1) is because the data I'm summing from will always be on Sheet 1 so I'm trying to reference the range D:D and I:I on that sheet.
Anyone have a solution?