I need to modify this code I used in another workbook, to copy and paste columns, but leave out rows that do not contain "Yes" in a different column in the same row.
Basically I want it to take each cell in a column, and copy and paste if in another column, same row has "Yes".![]()
Sub Button1_Click() ' ' CopyOpenItems Macro ' Copy open items to sheet. ' ' Keyboard Shortcut: Ctrl+Shift+O ' Dim fDialog As Office.FileDialog Dim varFile As Variant Dim wbExport As Workbook 'workbook from where the data is to Copied Dim wbImport As Workbook 'workbook where the data is to be Pasted Dim wsExport As Worksheet 'worksheet from where the data is to Copied Dim wsImport As Worksheet 'workbook where the data is to be Pasted Dim strExportName As String 'name of the workbook from where data is copied Dim strImportName As String 'name of the workbook where the data is to be Pasted Dim lngLastRow As Long Dim lngLastRow2 As Long Dim intColNum As Integer Dim objTable1 As ListObject 'open a workbook that has same name as the sheet name Set fDialog = Application.FileDialog(msoFileDialogFilePicker) With fDialog If .Show = True Then 'Add file chosen's name to a string. For Each varFile In .SelectedItems strExportName = varFile Next Else MsgBox "You clicked Cancel in the file dialog box." Exit Sub End If End With Set wbExport = Workbooks.Open(strExportName) Set wsExport = wbExport.Sheets(1) With wsExport lngLastRow = .Range("A" & .Rows.Count).End(xlUp).Row End With Set wbImport = ThisWorkbook Set wsImport = wbImport.ActiveSheet intColNum = WorksheetFunction.Match("FLEET_ID", wsExport.Range("1:1"), 0) wsExport.Range(XL_ColToLetter(intColNum) & "2:" & XL_ColToLetter(intColNum) & lngLastRow).Copy wsImport.Range("C4:C" & lngLastRow).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False With wsImport lngLastRow2 = .Range("C" & .Rows.Count).End(xlUp).Row 'How many rows for table resize? End With Set objTable1 = wsImport.ListObjects(1) objTable1.Resize Range("A3:BY" & lngLastRow2) wbExport.Close End Sub Public Function XL_ColToLetter(ColumnNumber As Integer) As String If ColumnNumber < 27 Then ' Columns A-Z XL_ColToLetter = Chr(ColumnNumber + 64) Else XL_ColToLetter = Chr(Int((ColumnNumber - 1) / 26) + 64) & _ Chr(((ColumnNumber - 1) Mod 26) + 65) End If End Function
Example:
ID-----------Successful?
Fred---------Yes
Bob----------No
John---------No
Jake---------Yes
So it would copy Fred and Jake and paste those values into a worksheet on another workbook.
I am guessing I need to use some sort of for statement?
Bookmarks