为什么我收到错误"无法获取WorksheetFunction类的#tupookup属性"?此处出现错误:Seg = Application.WorksheetFunction.VLookup(Code, rng, 2, False)
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 :(得分:0)
尝试这个概念可能对你有所帮助
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