Hi
I want to autofilter the data and then copy this dynamic range and paste it to another sheet, however, I have an issue which is after filtering the data, the MACRO is copying the unfiltered data and leaves the filtered ones (which they are the one that I need to copy).
here is my code:
Sub cont()
Sheets("Items").Select
'To Identify if there is a Range or it is an empty one
Dim FF As Range
Dim BB As Integer
Set FF = Range(Range("d1"), Range("d1").End(xlDown))
FF.autofilter field:=4, Criteria1:="221311"
BB = WorksheetFunction.Count(FF.Cells.SpecialCells(xlCellTypeVisible))
If BB < 1 Then
'if no Data
MsgBox "No data available"
Sheets("Items").Select
ActiveSheet.ShowAllData
Sheets("Main").Select
Exit Sub
Else
'Now all the data are available, LETS COPY
Set rng = ActiveSheet.autofilter.Range
rng.Offset(3, 0).Resize(rng.Rows.Count - 3).Copy
'first will define the empty cell
Sheets("Analysis Basis").Select
Dim lastrow As Long
lastrow = Range("a1000000").End(xlUp).Row
Cells(lastrow + 1, 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
'second will paste
ActiveSheet.Paste
'TO remove all filters
Sheets("Items").Select
ActiveSheet.ShowAllData
Sheets("Main").Select
End If
End Sub
Bookmarks