Filter and sum variable length columns

Charles_

New Member
Joined
Dec 12, 2012
Messages
32
Hello,

I am writing a VBA macros and have run into an issue.

I need to be able to filter and sum specific rows. For example, on column "W" I have "CASH1" & "CASH2" and need to:

1: filter all CASH1, sum values in column "F" and paste in cell "AD1"
2. Filter all CASH2, sum values in column "F" and past in cell "AD2"

So far, I have been trying with the below without much success

Activesheet.range("w:w").autofilter field:=1, criteria1:="CASH1"
Columns("F:F").select
Range(F1048576").activate
active cell.formular1c1 = "=subtotal()"

Thanks for you help!
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
I think you only need to get the totals... no macro is needed.

Try this simple formulas:
in Ad1: =SUMIF(W:W,"CASH1",F:F)
in Ad2: =SUMIF(W:W,"CASH2",F:F)

FaJitAS here.
 
Upvote 0
I think you only need to get the totals... no macro is needed.

Try this simple formulas:
in Ad1: =SUMIF(W:W,"CASH1",F:F)
in Ad2: =SUMIF(W:W,"CASH2",F:F)

FaJitAS here.

Thank you Fajitas,

I am getting an Excel error however, "formula incorrect", any ideas why?

also, I need to write it in te VBA as it is part of my macros.

thanks!!
 
Upvote 0
Check your 'localization' ... this formula is in english.
In spanish (my native language) it reads: SUMAR.SI(...) the function NAME changes between languages.

ANY WAY... you should write function names for formulas in macros in english:

Try this:

Range("AD1").Formula = "=SUMIF(W:W,"CASH1",F:F)"
Range("AD2").Formula = "=SUMIF(W:W,"CASH2",F:F)"

This code should put the formulas you want in place.
 
Last edited:
Upvote 0
Hi Fajitas!

Thanks for your help, sorry I did not reply earlier!

Your suggestion helped me figure out a sollution!

Thanks!
 
Upvote 0

Forum statistics

Threads
1,216,577
Messages
6,131,511
Members
449,653
Latest member
andz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top