首先我的代码:
Option Explicit
Sub UpdateCandidates()
Application.ScreenUpdating = False
Dim wks As Worksheet, wks2 As Worksheet
Dim Lastrow As String, Lastrow2 As String
Dim Rng As Range, i As Long, Rng2 As Range, i2 As Long
Dim cell As Variant, cell2 As Variant
Set wks = ThisWorkbook.Worksheets("Candidates")
Lastrow = wks.Range("B" & Rows.Count).End(xlUp).Row
If Lastrow > 1 Then
cell = wks.Range("B2:B" & Lastrow).Value
i = 1: Set Rng = Nothing
While i <= Lastrow
For i = i To Lastrow
Set wks2 = ThisWorkbook.Worksheets("Job live")
Lastrow2 = wks2.Range("A" & Rows.Count).End(xlUp).Row
If Lastrow2 > 1 Then
cell2 = wks2.Range("A2:A" & Lastrow2).Value
i2 = 1: Set Rng2 = Nothing
While i2 <= Lastrow2
For i2 = i2 To Lastrow2
If cell = cell2(i2, 1) Then
MsgBox ("found")
End If
Next
Wend
End If
Next
Wend
End If
Application.ScreenUpdating = True
End Sub
这基本上可以工作并比较两列,但最后它显示错误:
“下标超出范围”
我因为 <= Lastrow
而没有't understand why. I thought it'但是修复到 < Lastrow
并没有改变任何东西 .
我还想将第一张到第二张的值复制到特定的单元格 . 并在我的第二张纸的单元格下方插入一行 .
我也不明白为什么我必须将单元格与 cell2(i2,1)
进行比较,而不是将单元格与 cell2
进行比较 . 如果我将cell与cell2进行比较,则表示类型不匹配 . 如果我在工作表中输入第二个值,我会遇到同样的错误 .
我的代码出了什么问题?
1 回答
我看到了你的代码,这是一个提案