Run Through Cell value and pull data to Another workbook

Haree

Board Regular
Joined
Sep 22, 2019
Messages
146
Office Version
  1. 2016
Hello

Source Workbook : "Daily Sheet"
Source Location : Desktop

Destination Workbook : Return Items
Destination Location : D Drive

I have 12 sheets in the source workbook, one for each month
In each worksheet i have the following data
Column H: Date
Column I : Category
Column J : Party Name
Column K : Particulars
Column L: Bill Value
Column M: Quantity
Column N : Return Qty

If Column I : Category is "Returned Items" (I have a data validation) , i want that particular rows items from column H to Column N copied to the new workbook
I want this for all the worksheets in the source sheet
All the data can be together in the destination workbook
 
DateCategory
01-06-2020​
01-06-2020​
HDFC
01-06-2020​
HDFC
01-06-2020​
HDFC
01-06-2020​
Advance Closed
01-06-2020​
Advance Closed
01-06-2020​
Advance Closed
01-06-2020​
Advance Closed
01-06-2020​
Returned Items
01-06-2020​
Repairs Paid
01-06-2020​
Returned Items
01-06-2020​
Expenses
01-06-2020​
Google Pay
01-06-2020​
Expenses
 
Upvote 0

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Have sent you a copy, That Column might have blank cells also, ie I column
 
Upvote 0
Ok, didn't realize that Category could be empty. This version does a better job.
VBA Code:
Sub collectReturnedItems_traced()
    'Purpose: Read all sheets in Source and copy the category "Returned Items" rows

    Dim ws      As Worksheet
    Dim rs      As Worksheet
    Dim source  As Workbook
    Dim nm          As String
    Dim sourceRow   As Long
    Dim returnRow   As Long
    Dim column      As Long
    Dim category    As String
    Dim nbrCopied   As Long
    
    nm = ThisWorkbook.Path & "\Source.xlsx"
    Set source = Workbooks.Open(nm)
    Debug.Print source.FullName, source.Worksheets.Count; " Sheets"
    
    returnRow = 2
    Set rs = ThisWorkbook.Worksheets(1)
    
    For Each ws In source.Worksheets
        Debug.Print ws.Name, ws.Range("I1").CurrentRegion.Address(0, 0)
        
        If ws.Name <> "Debtors" And ws.Name <> "Total" Then
            nbrCopied = 0
            
            For sourceRow = 2 To ws.Range("I1").CurrentRegion.Rows.Count
                category = ws.Cells(sourceRow, "I")
                
                If category = "Returned Items" Then
                    nbrCopied = nbrCopied + 1
                    For column = 8 To 14
                        rs.Cells(returnRow, column).Value = _
                            ws.Cells(sourceRow, column).Value
                    Next column
                    returnRow = returnRow + 1
                End If

            Next sourceRow
            Debug.Print , sourceRow - 2; " rows read, "; _
                        nbrCopied; " rows copied."
        End If
    Next ws
End Sub
 
Upvote 0
Glad I could help. To tidy things up you might consider to remove the "_traced" and comment out (put a ' in front of) the debug.print statements.
 
Upvote 0

Forum statistics

Threads
1,214,636
Messages
6,120,664
Members
448,976
Latest member
sweeberry

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