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

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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