How to ignore the filtered data to prevent in copying the header?

jkevz07

New Member
Joined
Nov 8, 2022
Messages
1
Office Version
  1. 2019
Platform
  1. Windows
I have VBA code, it works when the filter date requirement is complete but if it's not complete, it will copy the header instead. Please check my code below:


Sub Macro7()
'
' Macro7 Macro
'

Dim LastRow As Long
On Error Resume Next
Range("c6").Select
Sheets("Ref2").Select
ActiveSheet.Range("$A$1:$O$168").AutoFilter Field:=3, Criteria1:=Sheets("NOV 2022").Range("E1").Value
ActiveSheet.Range("$A$1:$O$168").AutoFilter Field:=4, Criteria1:=Sheets("NOV 2022").Range("A6").Value
LastRow = Range("E" & Rows.Count).End(xlUp).Row
Range("E2:O" & LastRow).SpecialCells(xlCellTypeVisible).Select
Selection.copy
Sheets("NOV 2022").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.SmallScroll Down:=21
Sheets("Ref2").Select
ActiveSheet.Range("$A$1:$O$168").AutoFilter Field:=4, Criteria1:=Sheets("NOV 2022").Range("A37").Value
LastRow = Range("E" & Rows.Count).End(xlUp).Row
Range("E2:O" & LastRow).SpecialCells(xlCellTypeVisible).Select
Selection.copy
Sheets("NOV 2022").Select
Range("C37").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.SmallScroll Down:=21
Range("C58").Select
Sheets("Ref2").Select
ActiveSheet.Range("$A$1:$O$168").AutoFilter Field:=4, Criteria1:=Sheets("NOV 2022").Range("A58").Value
LastRow = Range("E" & Rows.Count).End(xlUp).Row
Range("E2:O" & LastRow).SpecialCells(xlCellTypeVisible).Select
Selection.copy
Sheets("NOV 2022").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.SmallScroll Down:=27
Range("C93").Select
Sheets("Ref2").Select
ActiveSheet.Range("$A$1:$O$168").AutoFilter Field:=4, Criteria1:=Sheets("NOV 2022").Range("A93").Value
LastRow = Range("E" & Rows.Count).End(xlUp).Row
Range("E2:O" & LastRow).SpecialCells(xlCellTypeVisible).Select
Selection.copy
Sheets("NOV 2022").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,224,813
Messages
6,181,116
Members
453,021
Latest member
Justyna P

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