M
manfareed
Hi ,
I have a spreadsheet with a summary sheet with 3 branch tabs.
I have the following code which filters for the word "visits" in the 3
branch tabs and subtotals the values next to the word and places the total in
the summary sheet.
Sub Filter_All_Visits()
Dim ws As Object
For Each ws In Worksheets
If ws.name <> "Summary" And ws.name <> "Totals by Branch" Then
ws.Range("B2").AutoFilter Field:=2, Criteria1:="Visits"
End If
Next ws
Sheets("Summary").Select
Range("C5").Select
ActiveCell.FormulaR1C1 =
"=SUBTOTAL(9,Birmingham!R[-2]C:R[5000]C,Reading!R[-2]C:R[5000]C,Nottingham!R[-2]C:R[5000]C)"
Range("C5").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("D5").Select
ActiveCell.FormulaR1C1 = _
"=SUBTOTAL(9,Birmingham!R[-2]C:R[5000]C,Reading!R[-2]C:R[5000]C,Nottingham!R[-2]C:R[5000]C)"
Range("D5").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
For Each ws In Worksheets
If ws.name <> "Summary" And ws.name <> "Totals by Branch" Then
ws.Range("B2").AutoFilter
End If
End Sub
My question is how do I make the code more dynamic i.e. if more branch tabs
are added. Also in the subtotal I have the row value as "5000". I want to do
away with putting this in.
Thanks
I have a spreadsheet with a summary sheet with 3 branch tabs.
I have the following code which filters for the word "visits" in the 3
branch tabs and subtotals the values next to the word and places the total in
the summary sheet.
Sub Filter_All_Visits()
Dim ws As Object
For Each ws In Worksheets
If ws.name <> "Summary" And ws.name <> "Totals by Branch" Then
ws.Range("B2").AutoFilter Field:=2, Criteria1:="Visits"
End If
Next ws
Sheets("Summary").Select
Range("C5").Select
ActiveCell.FormulaR1C1 =
"=SUBTOTAL(9,Birmingham!R[-2]C:R[5000]C,Reading!R[-2]C:R[5000]C,Nottingham!R[-2]C:R[5000]C)"
Range("C5").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("D5").Select
ActiveCell.FormulaR1C1 = _
"=SUBTOTAL(9,Birmingham!R[-2]C:R[5000]C,Reading!R[-2]C:R[5000]C,Nottingham!R[-2]C:R[5000]C)"
Range("D5").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
For Each ws In Worksheets
If ws.name <> "Summary" And ws.name <> "Totals by Branch" Then
ws.Range("B2").AutoFilter
End If
End Sub
My question is how do I make the code more dynamic i.e. if more branch tabs
are added. Also in the subtotal I have the row value as "5000". I want to do
away with putting this in.
Thanks