[英]vba vlookup another sheet
有人知道如何修復這些代碼嗎? 運行時錯誤'1004':應用程序定義或對象定義的錯誤
我如下更改了代碼。.仍然無法正常工作..
Sub Testing()
Dim DRACCT As String
Dim DR24 As Variant
Dim sh1, sh2 As Workbook
Dim Lastrow As Long
Dim i As Long
Lastrow = Range("A10000000").End(xlUp).Row
Set sh1 = ThisWorkbook.Worksheets("Sheet1")
Set sh2 = ThisWorkbook.Worksheets("Sheet2")
'On Error Resume Next
For i = 2 To Lastrow
DRACCT = sh1.Cells(i, 66).Value
DR24 = Application.VLookup(DRACCT, sh2.Range("A:B"), 2, False)
If Not IsError(DR24) Then
sh1.Cells(i, 68).Value = DR24
Else ' do nothing
End If
Next i
End Sub
兩個問題
只有1045876
行而不是10000000
這是您當前的錯誤。
下一個錯誤將是因為您正在嘗試將工作表設置為工作簿變量
編碼
Sub Testing()
Dim DRACCT As String
Dim DR24 As Variant
Dim sh1 As Worksheet, sh2 As Worksheet
Dim Lastrow As Long
Dim i As Long
Lastrow = Range("A1046876").End(xlUp).Row
Set sh1 = ThisWorkbook.Worksheets("Sheet1")
Set sh2 = ThisWorkbook.Worksheets("Sheet2")
'On Error Resume Next
For i = 2 To Lastrow
DRACCT = sh1.Cells(i, 66).Value
DR24 = Application.VLookup(DRACCT, sh2.Range("A:B"), 2, False)
If Not IsError(DR24) Then
sh1.Cells(i, 68).Value = DR24
Else ' do nothing
End If
Next i
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.