Joh*_*n W 2 excel vba find excel-vba vlookup
下午好,
是否可以Find
从范围的底部开始并进行处理?我想要的是我的代码首先找到一个位于主列表上的记录号.一旦找到记录编号,我希望它将该处理名称(offset
记录编号的一个)分配给变量,然后在主列表中搜索具有相同名称的第一笔交易.
目前,我有代码找到记录号,将交易名称分配给变量,然后循环每个单元格直到找到匹配项.虽然这种方式有效,但循环处理时间明显慢于查找处理时间,我正在寻找最快的解决方案.
如果反向查找不可能,vlookup会工作吗?可能是,创建一个从记录号上方开始1行的范围到顶部并让vlookup找到最后一次出现?
任何帮助表示赞赏.
PendingBRow = ThisWorkbook.Sheets("PendingLog").Range("A65000").End(xlUp).Row
MasterBRow = ThisWorkbook.Sheets("MasterLog").Range("A65000").End(xlUp).Row
For D = 2 To PendingBRow
With ThisWorkbook.Sheets("PendingLog").Range("A" & D)
PendingRecNum = .Value
PendingDealName = .offset(0, 3).Value
PDLenght = Len(PendingDealName) - 4
PendingDealName = Left(PendingDealName, PDLenght)
PendingDealName = UCase(PendingDealName)
PendingDealName = Trim(PendingDealName)
End With
With ThisWorkbook.Sheets("MasterLog").Range("B2:B" & MasterBRow)
Set c = .Find(PendingRecNum, LookIn:=xlValues)
If Not c Is Nothing Then
firstRow = c.Row - 1
O = 1
Do Until firstRow = O
LastWorkedBy = ThisWorkbook.Sheets("MasterLog").Range("E" & firstRow).offset(0, 20)
MasterRecNum = ThisWorkbook.Sheets("MasterLog").Range("E" & firstRow).offset(0, -3).Value
dealName = ThisWorkbook.Sheets("MasterLog").Range("E" & firstRow).Value
dealName = Left(dealName, 10)
dealName = UCase(dealName)
dealName = Trim(dealName)
If PendingDealName = dealName Then
MasterLastWorkedBy = LastWorkedBy
ThisWorkbook.Sheets("PendingLog").Range("A" & D).offset(0, 19).Value = MasterLastWorkedBy
firstRow = O
Else
firstRow = firstRow - 1
End If
Loop
End If
End With
Next D
Run Code Online (Sandbox Code Playgroud)
Gar*_*ent 15
这将FIND()从底部:
Sub FindFromTheBottom()
Set a = Range("A:A").Find("Test", after:=Cells(1, 1), searchdirection:=xlPrevious)
MsgBox a.Address(0, 0)
End Sub
Run Code Online (Sandbox Code Playgroud)