2017-08-16 30 views
0

「WorksheetFunctionクラスのVLookupプロパティを取得できません」というエラーが表示されるのはなぜですか?エラーが発生し、ここで:Seg = Application.WorksheetFunction.VLookup(Code, rng, 2, False)私のVLookupが機能しないのはなぜですか?

Sub RateCode() 
Dim I As Long 
Dim endRow As Long 
Dim Rate_Code() As Variant 
Dim ws As Worksheet 
Dim ws2 As Worksheet 
Dim rng As Range 
Dim Seg As String 
Set ws2 = Worksheets("Segment") 
Set ws = Worksheets("Sheet1") 
Set rng = ws2.Range("A1:B1300") 
     With ws 
     endRow = Sheet1.Range("A999999").End(xlUp).Row 
     endRow = endRow 
     Rate_Code = Sheet1.Range("F3:F" & endRow) 
     For I = LBound(Rate_Code) To UBound(Rate_Code) 
      Code = Rate_Code(I, 1) 

      If Len(Code) = 5 Then 
       Code = "'" & Mid(Code, 3, 2) 
       Cells(I + 2, 7).Value = Code 
      Else 
       Code = "'" & Left(Code, 2) 
       Cells(I + 2, 7).Value = Code 
      End If 
      Seg = Application.WorksheetFunction.VLookup(Code, rng, 2, False) 
      Seg = Cells(I + 2, 8).Value 
     Next I 
    End With 
End Sub 
+0

に役立つかもしれないそして、あなたが見直している[これら](https://stackoverflow.com/search?q=Unable+to+ +ワークシート+関数+クラスの+ VLookup +プロパティ+を取得します)? – pnuts

+0

@pnuts私はそれらの答えを見てきましたが、私はまだ苦労しています。 – Anthony

+0

@Anthony vlookupで戻り値を返す 'code'(参照値)をチェックし、' seg'に値を格納してください。 - 参照値をセルに格納しようとします。 – Ashok

答えて

0

この概念を試してみてくださいuの

Sub RateCode() 
Dim I, y As Long 

    Dim endRow As Long 
    Dim Rate_Code() As Variant 
    Dim ws As Worksheet 
    Dim ws2 As Worksheet 
    Dim rng As Range 
    Dim Seg As String 
    Set ws2 = Worksheets("Segment") 
    Set ws = Worksheets("Sheet1") 
    Set rng = ws2.Range("A1:B1300") 
    With ws 

      lr = ws.Range("F" & Rows.Count).End(xlUp).Row 

     For I = 3 To lr 
      Code = Rate_Code(I, 1) 
      If Len(Code) = 5 Then 
      Code = "'" & Mid(Code, 3, 2) 
      Cells(I + 2, 7).Value = Code 
      Else 
      Code = "'" & Left(Code, 2) 
      Cells(I + 2, 7).Value = Code 
      End If 
      y = 8 
      Cells(I, y) = Application.WorksheetFunction.VLookup(Code, rng, 6, 0) 
     Next I 
     End With 
    End Sub 
関連する問題