Meet criteria in one worksheet and copy row with criteria to new workbook

aylafan

New Member
Joined
Apr 13, 2011
Messages
20
I'm trying to figure out how to loop/search through one folder with several workbooks that contain (Sheet: Data) that meets criteria "Yes" in column "K" and then copy all those rows that meet this criteria in my Master Summary.xlsm workbook (Sheet: CapEx) starting at row 2.

I would appreciate it if anyone can help me solve this problem.

Here are several codes I used in my Excel project, but I don't know how to combine these 2 codes together to meet my above need.

Code 1: Copy rows that meets a certain criteria in one worksheet to another worksheet.
Code:
Sub CopyData()
Application.ScreenUpdating = False
Dim LR As Long, i As Long, j As Long
With Sheets("Data")
    LR = .Range("A" & Rows.Count).End(xlUp).Row
    For i = 2 To LR
        If .Range("K" & i).Value = "Yes" Then
            j = j + 1
            .Range("A" & i & ":K" & i).Copy Destination:=Sheets("CapEx").Range("A" & j)
        End If
    Next i
End With
Application.ScreenUpdating = True
End Sub

Code 2: Loop/search through one folder while summing rows/columns of specific cells from several workbooks to one workbook. (credit: daverunt)
Code:
Sub SumCells()
Application.ScreenUpdating = False
'Display Open Dialog to select file directory
filenames = Application.GetOpenFilename("Excel Files (*.xls*)," & _
"*.xls*", 1, "Select Files", "Open", False)
 
'If the user cancels file selection then exit
If TypeName(filenames) = "Boolean" Then
Exit Sub
End If
 
'Set xls as SourceFile
SourceFile = Dir("*.xls*")
Do While SourceFile <> ""
 
If Not (SourceFile) = "Master Summary.xlsm" Then
Workbooks.Open (SourceFile)
Set XLSFile = ActiveWorkbook
Worksheets("Summary").Select
    Set Rng = Sheets("Summary").Range("H5:J11,B28:B31,F28:F30,F33:F34,J35:J35,B41:B44,B50:B57,G41:G46,G50:G60,J61:J61")
    For Each Cell In Rng
 
    x = Cell.Address(0, 0)
    CurrValue = Cell.Value
 
 ThisWorkbook.Activate
 Worksheets("Summary").Select
 
    TotalValue = Range(x).Value
    Range(x).Value = TotalValue + CurrValue
 
 Next
 Windows.Application.CutCopyMode = False
 XLSFile.Close False
 
 End If
 SourceFile = Dir
  Loop
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,946
Latest member
JoseDavid

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