selectively copy rows from multiple sheets to another sheet

thedeacon

New Member
Joined
Mar 26, 2009
Messages
3
Apologies if this has been covered already - my search for prior posts did not turn up an exact solution.

Excel 2002, SP3
VB experience = very minimal

I have a worksheet with 12 tabs - one for each month of the year. On each month's tab, I have a TRANSACTION column, a DATE column, an AMOUNT column, and a CATEGORY column. I copy my credit card transactions to the month tabs throughout the year as they post online. I want to create a 13th tab that lists all of the rows from all of the tabs that have a specific value in the CATEGORY column. For example, I want the 13th tab to list all of the rows from all of the 12 month tabs that have a category of "gasoline". Also, I would like the data on the 13th tab to automatically update when new data is entered on any of the month tabs throughout the year.

Thanks in advance for any help with this.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hello and welcome,

this code will work for existing data

Code:
Sub COPY_TO_CATEGORY()
    Sheets(13).Range("A2:IV65536").ClearContents
    For MY_SHEETS = 1 To 12
        With Sheets(MY_SHEETS)
            .Rows(1).AutoFilter
            .Rows(1).AutoFilter Field:=4, Criteria1:="gasoline"
            If .Range("D" & Rows.Count).End(xlUp).Row > 1 Then
                .Range("A2:D" & .Range("D" & Rows.Count).End(xlUp).Row).SpecialCells(xlCellTypeVisible).Copy _
                    Sheets(13).Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
            End If
            .Rows(1).AutoFilter
        End With
    Next MY_SHEETS
End Sub

This starts by clearing the 13th TAB

Have assumed that Row 1 are headers, data starts in row 2 and COL D is where gasoline etc is. ALso assumed the 13th sheet is at the end of the TAB list.

How is the data entered in each sheet, this will determine where to place the code.
 
Upvote 0
Thank you for your reply.

A little more info that I did not mention:
- data is manually entered into the individual month tabs monthly
- the month tabs are named: JAN, FEB, MAR....DEC and are not the first 12 tabs in the workbook
- the tab where I want the info to go is named SUMMARY and is not the 13th tab in the workbook (and it is not the last tab either)

All the rest of your assumptions (header rows, etc) are valid.

Again, thanks for your help!
 
Upvote 0
Hello,

try

Code:
Sub COPY_TO_CATEGORY()
    Sheets(13).Range("A2:IV65536").ClearContents
    For MY_SHEETS = 1 To 12
        With Sheets(MY_SHEETS)
            .Rows(1).AutoFilter
            .Rows(1).AutoFilter Field:=4, Criteria1:="gasoline"
            If .Range("D" & Rows.Count).End(xlUp).Row > 1 Then
                .Range("A2:D" & .Range("D" & Rows.Count).End(xlUp).Row).SpecialCells(xlCellTypeVisible).Copy _
                    Sheets("SUMMARY").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
            End If
            .Rows(1).AutoFilter
        End With
    Next MY_SHEETS
End Sub

are your MONTH tab sheets always in the same place, if so then change

Code:
For MY_SHEETS = 1 To 12

to the relevant sheet tab numbers. If they can move about post back and I will supply another solution.
 
Upvote 0

Forum statistics

Threads
1,214,622
Messages
6,120,572
Members
448,972
Latest member
Shantanu2024

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