RoseChapman
New Member
- Joined
- Jun 12, 2018
- Messages
- 40
Hi all, I hope you can help me. I am trying to filter by a name "Tree" in column "E", and add the values in columns of columns "B", "D", "G" in another spreadsheet ("Sheet5"). My code is shown below, which it does the filtering but it pastes Columns A to F and I would like to paste only columns B, D and G. Please see my code below. Your help would be very much appreciated. Many thanks. Rose
Sub Filtering()
Dim Lastrow As Long
With Sheets("DATA_Sheet")
If .Range("E:E").Find("Tree", , xlValues, xlWhole, , , False) Is Nothing Then
MsgBox "No ""Changed"" rows found. ", , "No Rows Copied": Exit Sub
Else
Application.ScreenUpdating = False
.Columns(7).Hidden = True
Lastrow = .Range("G" & Rows.Count).End(xlUp).Row
.Range("E1:E" & Lastrow).AutoFilter Field:=1, Criteria1:="Tree"
.Range("A1:G" & Lastrow).SpecialCells(xlCellTypeVisible).Copy
Sheets("Sheet5").Range("A:G").PasteSpecial xlPasteValues, xlPasteSpecialOperationNone, False, False
.AutoFilterMode = False
'Position on cell A4
With Application
.CutCopyMode = False
.Goto Sheets("Sheet5").Range("A:G")
.ScreenUpdating = True
End With
.Columns(7).Hidden = False
MsgBox "All matching data has been copied.", , "Copy Complete"
End If
End With
End Sub
Sub Filtering()
Dim Lastrow As Long
With Sheets("DATA_Sheet")
If .Range("E:E").Find("Tree", , xlValues, xlWhole, , , False) Is Nothing Then
MsgBox "No ""Changed"" rows found. ", , "No Rows Copied": Exit Sub
Else
Application.ScreenUpdating = False
.Columns(7).Hidden = True
Lastrow = .Range("G" & Rows.Count).End(xlUp).Row
.Range("E1:E" & Lastrow).AutoFilter Field:=1, Criteria1:="Tree"
.Range("A1:G" & Lastrow).SpecialCells(xlCellTypeVisible).Copy
Sheets("Sheet5").Range("A:G").PasteSpecial xlPasteValues, xlPasteSpecialOperationNone, False, False
.AutoFilterMode = False
'Position on cell A4
With Application
.CutCopyMode = False
.Goto Sheets("Sheet5").Range("A:G")
.ScreenUpdating = True
End With
.Columns(7).Hidden = False
MsgBox "All matching data has been copied.", , "Copy Complete"
End If
End With
End Sub