Conditional SUM within VBA

Multi tool use
Conditional SUM within VBA
Large excel data which looks like this:
Now I have to create a macro for my data to filter. The filtration process is as follows:
First select the operator = mum and then select price as 1 and get sum of count column and then 2 and get sum of count column and so on....
then select operator = delhi and similarly select price as 1 and get sum of count column and then 2 and get sum of count column and so on
1 Answer
1
For mum,
=sumifs(c:c, d:d, 1, f:f, "mum")
=sumifs(c:c, d:d, 2, f:f, "mum")
=sumifs(c:c, d:d, 3, f:f, "mum")
...
For dehli,
=sumifs(c:c, d:d, 1, f:f, "dehli")
=sumifs(c:c, d:d, 2, f:f, "dehli")
=sumifs(c:c, d:d, 3, f:f, "dehli")
...
In VBA,
dim i as long, j as long, op as variant
op = array("mum", "dehli")
for i=lbound(op) to ubound(op)
for j=1 to application.max(range("d:d"))
debug.print application.sumifs(range("c:c"), range("d:d"), j, range("f:f"), op(i))
next j
next i
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Record Macro then generalise and optimise.
– PatricK
Jul 2 at 6:09