映射优化

时间:2017-01-03 15:16:13

标签: excel vba excel-vba

我有下面的代码可以使用,但需要很长时间才能完成(30K +记录)。关于如何加速的任何建议?

Sub PelsisMapping()
Dim sh1, sh2 As Worksheet
Dim startRow As Integer
Dim foundCell As Range

'Set sheets
'Sheet to Amend
Set sh1 = Sheets("STOCK PELSIS 1")
'Sheet that has mapping data
Set sh2 = Sheets("Mapping")

'set the start row for Sheet1
startRow = 4

'loop until column H of Sheet1 is blank
Do While sh1.Range("H" & startRow) <> ""

  'search id of column A of sheet2 from column H of Sheet2
  Set foundCell = sh2.Range("A:A").Find(sh1.Range("H" & startRow), LookIn:=xlValues)

  'If match id is found, add text in column U of Sheet1. overwriting what is already there
  If Not foundCell Is Nothing Then
    sh1.Range("U" & startRow) = foundCell.Offset(0, 1).Value
  End If

  'increase row
  startRow = startRow + 1
Loop
End Sub

0 个答案:

没有答案