abdelfattah
Well-known Member
- Joined
- May 3, 2019
- Messages
- 1,429
- Office Version
- 2019
- 2010
- Platform
- Windows
hello
i need help fixing this code from the firs time it works very well but when i run again filtered data in sheet "data" is gone and gives me runtime error 1004 no cells were found
thanks advance
i need help fixing this code from the firs time it works very well but when i run again filtered data in sheet "data" is gone and gives me runtime error 1004 no cells were found
VBA Code:
Sub CopyFiltered()
Dim src As Worksheet
Dim tgt As Worksheet
Dim filterRange As Range
Dim copyRange As Range
Dim lastRow As Long
Set src = ThisWorkbook.Sheets("DATA")
Set tgt = ThisWorkbook.Sheets("Sheet2")
src.AutoFilterMode = False
lastRow = src.Range("A" & src.Rows.Count).End(xlUp).Row
Set filterRange = src.Range("A1:F" & lastRow)
Set copyRange = src.Range("B2:F" & lastRow)
filterRange.AutoFilter field:=2, Criteria1:="=" & Range("F2").Value
copyRange.SpecialCells(xlCellTypeVisible).Copy tgt.Range("B6")
End Sub
thanks advance