I am fairly new to vba and trying to apply a formula that can do an average with 2 conditions on multiple worksheets.
It needs to be a formula and not a calcul as the data searched might change and the script must run only once.
The data itself is inside of column S in the sheets and the first condition is whether or not the number is superior to a set integer (found on the homepage of the Excel in F10)
The second condition is to check the group in which the data is from, it will always be a string and the range is found in column A the condition itself is inside a cell two columns before (see screenshot)
Screenshot of the formating
To resolve this problem I used a list of all worksheets of interest (in column 9 or I and row from 3)
And then I used INDIRECT as the adress for my AVERAGEIFS.
It made this formula
nb_ws = WorksheetFunction.CountA(Worksheets("Results").Columns("I:I"))
Worksheets("Results").Cells(11, 23).Formula2R1C1 = "=AVERAGEIFS(INDIRECT(""'""&R3C9:R" & nb_ws + 2 & "C9&""'!""&""S:S""),""'""&R3C9:R" & nb_ws + 2 & "C9&""'!""&""S:S"","">=""&'Homepage'!R10C6,INDIRECT(""'""&R3C9:R" & nb_ws + 2 & "C9&""'!""&""A:A""),RC[-3])"
As of now it doesn’t work and I really wonder if using a “for each” and making averages per sheets and only then making a general average would be better, I was advised by a coworker with more experience to avoid “for each” but it seems much simpler. We are allowed to modify all the sheets but shouldn’t touch the data itself.
Could you please confirm if I am on the right track or should I change my method ?
I am not looking for a solution but more of a method as I would like to truly understand what I do and how it works.
Thank you.