如何在没有1004错误的情况下过滤和填充可见单元格

时间:2015-05-31 07:11:22

标签: vba excel-vba excel

我正在尝试使用指定的关键字过滤A列,然后使用“Sub RunThis”在B列的可见单元格中填充一些文本 一旦我的关键字与任何行A不匹配,就会出现error1004。

你能建议我解决这个问题吗?

非常感谢你,

我的交叉发布 http://www.excelforum.com/showthread.php?t=1085681&p=4088366 http://www.ozgrid.com/forum/showthread.php?t=195012

Public LastRow As Long 
Sub RunThis() 
    LastRow = ActiveCell.SpecialCells(xlCellTypeLastCell).Row 
     'Suite1
     'Suite2
     'Suite3
     'Suite4
     'Suite5
    Suite6 
     'Suite7
     'Suite8
     'Suite9
     'Suite10
     'Suite11


End Sub 




 '==============================FIND===Suite6==================
Sub Suite6() 
    On Error Goto NEXT0 
     '============Search KeyWord 1 2
    ActiveSheet.Range("A:A").AutoFilter Field:=1, Criteria1:= _ 
    "=*S6R*", Operator:=xlOr, Criteria2:="=*Suite6/*" 
     ' Select target column to paste
    Range("D2:D" & LastRow).Select 
    Selection.SpecialCells(xlCellTypeVisible).Select 
     ' TargetText for this search
    Selection.FormulaR1C1 = "Suite-6" 
NEXT0: 
    On Error Goto NEXT2 
    ActiveSheet.Range("A:A").AutoFilter Field:=1, Criteria1:= _ 
    "=*Suite 6/*", Operator:=xlOr, Criteria2:="=*Suite_6/*" 
     ' Select target column to paste
    Range("D2:D" & LastRow).Select 
    Selection.SpecialCells(xlCellTypeVisible).Select 
     ' TargetText for this search
    Selection.FormulaR1C1 = "Suite-6" 
NEXT2: 
    On Error Goto NEXT3 
    ActiveSheet.Range("A:A").AutoFilter Field:=1, Criteria1:= _ 
    "=*Suite-6/*", Operator:=xlOr, Criteria2:="=*Suite6.*" 
     ' Select target column to paste
    Range("D2:D" & LastRow).Select 
    Selection.SpecialCells(xlCellTypeVisible).Select 
     ' TargetText for this search
    Selection.FormulaR1C1 = "Suite-6" 
NEXT3: 
    On Error Goto NEXT4 
    ActiveSheet.Range("A:A").AutoFilter Field:=1, Criteria1:= _ 
    "=*Suite 6.*", Operator:=xlOr, Criteria2:="=*Suite_6.*" 
     ' Select target column to paste
    Range("D2:D" & LastRow).Select 
    Selection.SpecialCells(xlCellTypeVisible).Select 
     ' TargetText for this search
    Selection.FormulaR1C1 = "Suite-6" 
NEXT4: 
    On Error Goto NEXT5 
    ActiveSheet.Range("A:A").AutoFilter Field:=1, Criteria1:= _ 
    "=*Suite-6.*", Operator:=xlOr, Criteria2:="=*Suite-6/*" 
     ' Select target column to paste
    Range("D2:D" & LastRow).Select 
    Selection.SpecialCells(xlCellTypeVisible).Select 
     ' TargetText for this search
    Selection.FormulaR1C1 = "Suite-6" 
NEXT5: 
End Sub 

1 个答案:

答案 0 :(得分:0)

这将解决您的潜在问题,而不会创建混乱的spaghetty代码或留下过滤器。作为奖励,我认为它甚至会有较低的运行时间和一些智慧,你可以让它循环通过套房1-11。

Order