2016-12-02 5 views
0

私はApplication.WorksheetFunctionという行にこのエラーが表示され続けています。何時間も話題を読んでいても、私はどこにもいないと感じています。 私はSheet2を参照している方法と関係がありますか?または、Application.WorksheetFunctionさんは何をすべきかを完全に理解していませんか?WorkSheet関数のクラスの一致プロパティを取得できません - 構文ですか?

Sub SearchForValues() 

i = 4 'starts the iterator at column D 

Do While Cells(1, i) <> "" 

    Dim l As Long, searchRange As String 
    n = 2 
     Do While Range("A" & n) <> ""  'loop until the last row of data in the first column 
     StartRow = Range("B" & n) 
     EndRow = Range("C" & n) 
     searchRange = "A" & StartRow & ":Q" & EndRow 
     l = Application.WorksheetFunction.Match(Cells(1, i), Worksheets("Sheet2").Range(searchRange), 0) 
     Range("D" & n) = l 
     n = n + 1 
    Loop 

i = i + 1 
Loop 
End Sub 

ここには、私が持っているデータのスクリーンショットがあります。列BとCは、私は1 and each cell across the top is a term I want to search for in that range.

+1

マッチのみ1次元配列上で動作を使用する方法の一例です。 1行または1列のいずれかです。 –

+0

@ScottCranerこれはたくさんの意味がある、ありがとう。範囲全体を検索するために使用できる別の関数はありますか? – eob

+0

VBA Find()を使用してください –

答えて

0

スコットCranerが既に
マッチのみ1次元配列に取り組んでいます」と彼のコメントにあなたの質問に答えシート上の行ごとにSheet2の上で検索したい行の範囲であり、どちらか「1行または1列」および「VBAの検索()」を使用します。ここで

あなたはRange.Find

Sub SearchForValues() 
    Application.ScreenUpdating = False 
    Dim Target As Range 
    Dim x As Long, y As Long 
    With Worksheets("Sheet1") 
     For x = 2 To .Cells(.Rows.Count, 1).End(xlUp).Row 
      For y = 4 To .Cells(1, .Columns.Count).End(xlToLeft).Column 
       Set Target = Worksheets("Sheet2").Range("A" & .Cells(x, "B").Value & ":Q" & .Cells(x, "C").Value) 
       .Cells(x, y).Value = Not Target.Find(.Cells(1, y).Value) Is Nothing 
      Next 
     Next 
    End With 
    Application.ScreenUpdating = True 
End Sub 
関連する問題