Microsoft Excel - Getting Run-Time error 1004 no cells found

Asked By Gerry on 13-Jul-11 05:24 PM
I've ued this macro for months with no issues, the filter I'm using typically filters no data. I want that blank filtered page copied and pasted to another sheet. I 've run the macro several times with old data and it seems to work. THe only thing I can think of is the format of the new data? Heres the VB,,any help would be appreciated

 Set wsNew = ThisWorkbook.Worksheets.Add
    wsNew.Name = "rates"
    
    Sheets("rates").Select
   
  
'Filters out the >=3.000, <=3.995, <=180origloanmonths, <=60 Remaining months
    Sheets("Fixed rate Orig test").Select
   Cells.EntireColumn.AutoFit
      Columns("J:M").Select
    Selection.delete Shift:=xlToLeft
      Columns("F:F").Select
    Selection.NumberFormat = "0.00"
    Selection.AutoFilter Field:=6, Criteria1:=">=3.000", Operator:=xlAnd, _
      Criteria2:="<=3.995"
    Selection.AutoFilter Field:=8, Criteria1:="<360", Operator:=xlAnd
    Selection.AutoFilter Field:=9, Criteria1:="<=60", Operator:=xlAnd
   
    ActiveSheet.UsedRange.Offset(0, 0).SpecialCells _
    (xlCellTypeVisible).Copy
    Sheets("rates").Select
    Range("A1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
      :=False, Transpose:=False
Jackpot . replied to Gerry on 13-Jul-11 09:32 PM
Hi Gerry

Here once you select ColF you are changing the number format

Columns("F:F").Select

After that without reselecting you are tryiung to autofilter. Remember othe current selection contains only one column but your autofilter criteria column goes as 6,7 and 8 and hence it returns the error...Either you want to reselect the used range and then try autofilter or modify the criteria column....
Gerry Chu replied to Jackpot . on 28-Mar-12 05:28 PM
Hi,
As crazy as it seems, I am experiencing the same issue again that I had in July of last year. Thanks to jackpot to the original response. I added a line to try to reselect the entire worksheet as Jackpot suggested, the filter returns zero lines(which is correct) but using the command below still gives me an error that no cells were found. I would still want this blank filtered results to be able to copy and paste into another sheet for further formatting or, perhaps a way to bypass the error ( which I dont think I should use) the funny thing is that in some earlier s/s's, using the same macro, it copies over the blank filtered worksheet without a hitch...I am not a macro guru by any stretch, would appreciate any help on this!

Regards,
Gerry

ActiveSheet.UsedRange.Offset(0, 0).SpecialCells _
    (xlCellTypeVisible).Copy



'creates a worksheet to paste all selected filtered rows
   
    Set wsNew = ThisWorkbook.Worksheets.Add
    wsNew.Name = "Fixed Int Rate Dist 10A"
   
 
    'changes tab color to blue
    Sheets("Fixed Int Rate Dist 10A").Select
    ActiveWorkbook.Sheets("Fixed Int Rate Dist 10A").Tab.ColorIndex = 5
   
   Set wsNew = ThisWorkbook.Worksheets.Add
    wsNew.Name = "rates"
    
    Sheets("rates").Select
   
  
'Filters out the >=3.5000, <=4.000, <=180origloanmonths, <=60 Remaining months
    Sheets("Fixed rate Orig test").Select
   Cells.EntireColumn.AutoFit
      Columns("J:M").Select
    Selection.delete Shift:=xlToLeft
      Columns("F:F").Select
    Selection.NumberFormat = "0.00"
   
    Cells.Select
    ActiveWorkbook.Save
   
    Range("A1").Select
   
    Selection.AutoFilter Field:=6, Criteria1:=">=3.500", Operator:=xlAnd, _
      Criteria2:="<=4.000"
    Selection.AutoFilter Field:=8, Criteria1:="<360", Operator:=xlAnd
    Selection.AutoFilter Field:=9, Criteria1:="<=60", Operator:=xlAnd
   
    ActiveSheet.UsedRange.Offset(0, 0).SpecialCells _
    (xlCellTypeVisible).Copy
    Sheets("rates").Select
    Range("A1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
      :=False, Transpose:=False
     
     'Offset 2 leaves one line empty
'R1C5 = Row 1 Column 5 i.e. E1
'R[-1] equals one rows less than the cell the formula is in
'so if the formula is in cell E50 the formula will be E2:E48

     Range("E65536").End(xlUp).Offset(1, 0).FormulaR1C1 = "=SUM(R1C5:R[-1]C)"
   Columns("E:E").EntireColumn.AutoFit