Stop copy-paste if the filtered range has no data

kpmsivaprakasam2003

New Member
Joined
Jan 28, 2020
Messages
9
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
  5. 2011
  6. 2010
  7. 2007
Platform
  1. Windows
Hi,

I am working Excel 2013,

I need the Autofilter "#N/A" in the "F" column, if filter the "#N/A" no data with the heading, "Goto 0:" code does...

but, my code not working, goto 0:

Sub testsss()
'Filter Insert and #N/A Copy and Paste
'VBA – Turn Off Autofilter From Code
If ActiveSheet.AutoFilterMode Then
ActiveSheet.AutoFilterMode = False 'ActiveSheet.Range("A1").AutoFilter ---> Turn On Autofilter
End If

'Auto Filter 2nd Column Blank Cells filter
Dim LastRow As Long
LastRow = Range("B" & Rows.Count).End(xlUp).Row

On Error Resume Next 'if filter then no data go next
ActiveSheet.Range("$A$1:$F" & LastRow).AutoFilter Field:=6, Criteria1:="#N/A" 'Not Applicable Cells filter then select visible cells
Range("$A$2:$F" & LastRow).SpecialCells(xlCellTypeVisible).Select

'Stop copy paste if the filtered range has no data
If Range("A1:F" & LastRow).SpecialCells(xlCellTypeVisible).Count > 1 Then
Range("$B$2:$D" & LastRow).SpecialCells(xlCellTypeVisible).Select
Selection.Copy
'Do Something Code.........
Application.CutCopyMode = False
Else
ActiveSheet.AutoFilterMode = False
GoTo 0:
End If

'Do Something Code.........

0:
End Sub


Kindly help me, thanks for advance

1638602413743.png



1638602454009.png
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hi
Why not to try
VBA Code:
On Error GoTo 0
 
Upvote 0
but, my code not working, goto 0:

Using go to like that is considered bad practice, you If statement should already be doing the bypassing of "Do something" code.
Be that as it may, get rid of the colon after your GoTo 0:, it should be just GoTo 0

Also as @mohadin pointed out, using GoTo 0 is easily confused with On Error Goto 0. It would be better to use a meaningful label and not "0:"
 
Upvote 0

Forum statistics

Threads
1,214,652
Messages
6,120,746
Members
448,989
Latest member
mariah3

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