filter/sort/subtotal via a macro

osaben

Board Regular
Joined
Mar 17, 2010
Messages
62
Office Version
  1. 365
Platform
  1. Windows
I'm really strugglling with developing a macro to do the following:

rows of 6 columns of figures and two columns of dates...would like to filter, sort & subtotal the data based on a range of dates in a date column. The column (date 1 or date 2) that I would need to filter on would vary based on what subtotal I wanted to view.

once this is accomplished, I would like to take the subtotals and copy/paste/value it to a second sheet.

All the while being able to clear the sorts/subtotals once the information is viewed/used.

Any help would be GREATLY apprecitated!
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Here is the code that I have.....The sort & filter seem to be working. The subtototal is working. (although there is not visible outline)....I assume this is ok. But I am unable to get only the subtotals to copy to the second sheet.


Private Sub CommandButton1_Click()
' Apply advance filter
Range("g6").Select
Range("A6:H50000").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
Range("J1:K2"), Unique:=False
' Sort data
Range("A6:H50000").Sort Key1:=Range("G3"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

'Apply Subtotal
Selection.Subtotal GroupBy:=7, Function:=xlSum, TotalList:=Array(1, 2, 3, 4, _
5, 6), Replace:=True, PageBreaks:=False, SummaryBelowData:=True

End Sub
Private Sub CommandButton2_Click()
Range("g6").Select
Selection.RemoveSubtotal ' Remove subtotal
ActiveSheet.ShowAllData ' Remove Advanced filter
End Sub
Private Sub CommandButton3_Click()
' Apply advance filter
Range("g6").Select
Range("A6:H50000").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
Range("L1:M2"), Unique:=False
'Sort data
Range("A6:H50000").Sort Key1:=Range("h3"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
'Apply subtotal
Selection.Subtotal GroupBy:=8, Function:=xlSum, TotalList:=Array(1, 2, 3, 4, _
5, 6), Replace:=True, PageBreaks:=False, SummaryBelowData:=True
'Show all data
'ActiveSheet.ShowAllData
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,557
Messages
6,179,508
Members
452,918
Latest member
Davion615

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