copy and paste filter values based on array criteria getting error "NO CELLS FOUND"

srikanth sare

New Member
Joined
May 1, 2020
Messages
30
Office Version
  1. 2013
Platform
  1. Windows
  2. MacOS
  3. Mobile
  4. Web
The below code is copying filter values based on array criteria.

It works fine until when filter value doesnot exit in array getting error "NO CELLS FOUND"

help me in solving error and also any improvement in code
VBA Code:
Sub PLOT()
    On Error GoTo EH
    Application.Run "TurnOff"
    Sheet8.AutoFilterMode = False
    Sheet5.Unprotect "1818"
    Sheet5.Cells.Copy
    Sheet8.Range("A1").PasteSpecial xlPasteValues
    Sheet8.Range("A1").PasteSpecial xlPasteFormats
    Application.CutCopyMode = False
    Sheet9.Range("A6:EB9999").Clear

    Sheet9.Range("ED6:FG" & Range("FG9999").Row).ClearContents
    Dim lst, PasteCol1, PasteCol2, Cell As Long, FilterArray, FilterCol As Variant
    PasteCol1 = 134
    PasteCol2 = 135
    FilterArray = Array("UPD", "DF 1", "DF 2", "DF 3", "ALL", "N-ALL", "E", "U-REG", "REG", "A-RF", "RF", "A-TF", "I-TF", "E-TF", "CL", "DUM") ' FilterArray should be in order from the last value to be removed to the first value to be removed
    lst = Sheet8.Range("A6").CurrentRegion.Rows.Count
    For Each FilterCol In FilterArray
    Sheet8.Rows("5:5").AutoFilter Field:=2, Criteria1:=FilterCol, Operator:=xlFilterValues
    Sheet8.Range("C6:C" & lst).SpecialCells(xlCellTypeVisible).Copy
    Sheet9.Cells(6, PasteCol1).PasteSpecial xlPasteValues
    Sheet8.Range("M6:M" & lst).SpecialCells(xlCellTypeVisible).Copy
    Sheet9.Cells(6, PasteCol2).PasteSpecial xlPasteValues
    Application.CutCopyMode = False
    PasteCol1 = PasteCol1 + 2
    PasteCol2 = PasteCol2 + 2
    Next FilterCol
    
CleanUp:         On Error Resume Next
         Application.Run "TurnOn"
         Sheet8.Cells.Clear
   Sheet5.Protect "1818", DrawingObjects:=False, Contents:=True, Scenarios:=False, UserInterFaceOnly:=True, AllowFormattingCells:=True, AllowFormattingColumns:=True, AllowFormattingRows:=True, AllowSorting:=True, AllowFiltering:=True
   Exit Sub
EH: Debug.Print Err.Description  ' Do error handling
   MsgBox "Sorry, an error occured." & vbCrLf & Err.Description, vbCritical, "Error!"
   Resume CleanUp

End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Forum statistics

Threads
1,215,636
Messages
6,125,952
Members
449,276
Latest member
surendra75

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