I am trying to turn this formula into VBA code:
=COUNTIFS('Report'!$J:$J,"=In Force")
However, I have acquired the column in the 'Report' file that I will be extracting the data from. The column number it stores in variable ColNum
. I need to ensure that it extracts data from the column variable that I have found, and from the 'Report' File.
Here is my code so far (I know it is not correct):
ActiveCell.FormulaR1C1 = "=COUNTIFS(Report'!$I:$I,"=In Force")"
Any help would be greatly appreciated!!!
If you know the number of the column (in the ColNum variable) that you wish to sum then you can use:
ActiveCell.FormulaR1C1 = "=COUNTIFS('Report'!C" & ColNum & ":C" & ColNum & ",""=In Force"")"
If the name of the sheet is also in a variable, ReportName, then the formula is:
ActiveCell.FormulaR1C1 = "=COUNTIFS('" & ReportName &"'!C" & ColNum & ":C" & ColNum & ",""=In Force"")"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.