2016-06-14 11 views
0

は、ここに私のコードです。 「タイプの不一致」エラーが発生しました。 "st = Sheets(..."行を.Textの代わりに.Valueに変更するか、.Find行をLookIn:= xlFormulasの代わりにLookin:= xlValuesに変更すると、同じエラーが発生します。二つの組み合わせ。Range.Find型の不一致エラー

Private Sub CommandButton1_Click() 
Dim rowLast As Integer 
Dim str As String 
Dim cell As Range 

Sheets("Itemschedule").ListObjects("Table2").Range.AutoFilter 
rowLast = Sheets("Itemschedule").Cells(Rows.Count, "A").End(xlUp).Row 
Sheets("Itemschedule").ListObjects("Table2").Resize Range("A1:E" & rowLast) 
Sheets("Itemschedule").Range("A" & rowLast + 1 & ":E" & Rows.Count).ClearContents 
For i = 2 To rowLast 
    str = Sheets("Itemschedule").Cells(i, "A").Text 
    With Sheets("Whereused").Range("B:B") 
     Set cell = .Find(What:=str, After:=.Range("B1"), LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False) 
    End With 
    If cell Is Nothing Then 
     Sheets("Itemschedule").Cells(i, "E").Value = "FALSE" 
    Else 
     Sheets("Itemschedule").Cells(i, "E").Value = "TRUE" 
    End If 
Next 
On Error Resume Next 
Sheets("Itemschedule").ListObjects("Table2").Range.AutoFilter 
Sheets("Itemschedule").Range("A1:E" & rowLast).AutoFilter Field:=1, Criteria1:="FALSE" 
Sheets("Itemschedule").Range("A1:E" & rowLast).SpecialCells(xlCellTypeVisible).EntireRow.Delete 
Sheets("Itemschedule").ListObjects("Table2").Resize Range("A1:E" & rowLast) 
Sheets("Itemschedule").ListObjects("Table2").Range.AutoFilter 

End Sub 

私はそれが愚かな何かだと確信しています。多くのことをしようとしたが、それを把握することはできませんよきた。
助けてください。

+0

'型名(.Find(何のDebug.Printしよう:= strの、後:。=範囲( "B1")、のlookin:= xlValues、ルックアット:= xlWhole、SearchOrder:= xlByRows、SearchDirection:= xlNextを、MatchCase:= False、SearchFormat:= False)) '、オブジェクトがどんなタイプのオブジェクトが生成されているのかを考えてもらいたいと思っています...おそらくエラー、ちょうど推測 – Rosetta

+1

なぜ「Sheets(" Itemschedule ")? ( "E2:E"&rowLast)= "=" = ISNUMBER(MATCH(A2、使用場所はB:B、0) ( "Item schedule")Range( "E2:E"&rowLast).Value'? – Jeeped

+0

@Jeeped、あなたの方法は好きですが、単純に見えますが、式の行に "Application defined or object defined error"がありますか? –

答えて

1

エラーは、Afterパラメータが検索範囲内にないためです。この部分:

With Sheets("Whereused").Range("B:B") 
     Set cell = .Find(What:=str, After:=.Range("B1"), LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False) 
    End With 

あるべき:

With Sheets("Whereused").Range("B:B") 
     Set cell = .Find(What:=str, After:=Sheets("Whereused").Range("B1"), LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False) 
    End With 

さもなければ.Range("B1")Range("B:B")に対してであり、したがってC1を指します。

0

辞書が重複を見つけることで、より効率的です値。

Sub CommandButton1_Click() 
 
    
 
    Dim keyword As String, keyvalue As Variant 
 
    Dim rowLast As Long, x As Long 
 
    Dim dicItems 
 
    Set dicItems = CreateObject("scripting.dictionary") 
 
    
 
    With Sheets("Whereused") 
 
     rowLast = .Cells(Rows.Count, "A").End(xlUp).Row 
 
     For x = 2 To rowLast 
 
      keyword = .Cells(x, 2) 
 
      keyvalue = .Cells(x, 2) 
 
      'Add Key Value pairs to Dictionary 
 
      If Not dicItems.Exists(keyword) Then dicItems.Add keyword, keyvalue 
 
     Next 
 
    End With 
 

 
    With Sheets("Itemschedule") 
 
     rowLast = .Cells(Rows.Count, "A").End(xlUp).Row 
 
     For x = 2 To rowLast 
 
      keyword = .Cells(x, 1) 
 
      .Cells(x, 2) = dicItems.Exists(keyword) 
 
     Next 
 
    End With 
 
End Sub

しかしItemschedule列B.

= COUNTIF(表1 [[#この行]、[アイテム]]、表2 [[#ヘッダ]でワークシートの数式を置き、それを行うための適切な方法、[アイテム]])> 0