Search VBA Excel,为了节省处理时间,我应该在这个循环中使用什么方法进行搜索?
好的,这是我创建的代码(在Stackoverflow用户的帮助下),它比较了两个工作表,一个银行对账单(存款和信用)和一个内部创建的报告(6月)。If语句正在检查两张表上的日期和转账金额是否匹配。当满足此条件时,将突出显示存款和信贷表行,并且来自wsPB的匹配位置将写入存款金额旁边的列中 基本上,这段代码可以工作,但是非常慢,因为wsPB(June PB INS)有70k行。我可以使用搜索功能来加快速度吗Search VBA Excel,为了节省处理时间,我应该在这个循环中使用什么方法进行搜索?,search,find,Search,Find,好的,这是我创建的代码(在Stackoverflow用户的帮助下),它比较了两个工作表,一个银行对账单(存款和信用)和一个内部创建的报告(6月)。If语句正在检查两张表上的日期和转账金额是否匹配。当满足此条件时,将突出显示存款和信贷表行,并且来自wsPB的匹配位置将写入存款金额旁边的列中 基本上,这段代码可以工作,但是非常慢,因为wsPB(June PB INS)有70k行。我可以使用搜索功能来加快速度吗 Sub StackCombined() Dim TransDate As String
Sub StackCombined()
Dim TransDate As String
Dim TransAmt As Long
Dim PBINSDate As String
Dim PBINSAmt As Long
Dim wsPB As Worksheet
Dim Sht1LastRow As Long, Sht2LastRow As Long
Dim x2 As Long, x2count As Long, x1 As Long, x1count As Long
' Sht1LastRow finds the last row of Deposits and Credits with a value
Sht1LastRow = Sheets("Deposits And Credits").Cells(10000, 1).End(xlUp).Row
' Sht2LastRow finds the last row of June PB INS with a value
Sht2LastRow = Sheets("June PB INS").Cells(100000, 1).End(xlUp).Row
' Call worksheet June PB INS just wsPB
Set wsPB = Sheets("June PB INS")
With Sheets("Deposits And Credits")
For x1 = 2 To Sht1LastRow
For x2 = 2 To Sht2LastRow
'TransDate is the transaction date recorded from the bank
TransDate = Sheets("Deposits And Credits").Cells(x1, 1).Value
'PBINSDate is the transaction date recorded internally through EPIC
PBINSDate = Sheets("June PB INS").Cells(x2, 1).Value
'TransAmt is the bank statements amount of the transaction
TransAmt = Sheets("Deposits And Credits").Cells(x1, 3).Value
'The Dates must match
'The amount must either column 2, single record, OR column 15, daily record
'if these two conditions are met, highlight the bank statement and record where the match was found
If TransDate = PBINSDate _
And (TransAmt = Sheets("June PB INS").Cells(x2, 2) _
Or _
TransAmt = Sheets("June PB INS").Cells(x2, 15) _
) _
Then
.Cells(x1, 12).Value = wsPB.Cells(x2, 1).Address(True, True, xlA1, True) And Sheets("Deposits And Credits").Rows(x1 & ":" & x1).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 5296274
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End If
Next x2
Next x1
End With
End Sub