AAP
Member
In the below code variable prodg which is undimensional array captures the results and paste it back to worksheet one by one.
I would like that variable prodg hold the results of all the rows and paste it back once to worksheet not row by row. The reason just to increase the speed of the code. I uploaded a sample file with just 768 rows to find but in actual I have rows of about 900,000 which takes a lot of time. Can someone help me?
[/
Sub testusingranges()
Debug.Print Time
Application.ScreenUpdating = False
Dim MPNBase As Range, MPN As Range, FindMPN As Range
Dim prodg As Variant
Dim matchnumber As Long
Set MPNBase = ThisWorkbook.Worksheets("MPNBase").Range("Table1")
Set MPN = ThisWorkbook.Worksheets("MPNBase").Range("A2:A1000")
Set FindMPN = ThisWorkbook.Worksheets("FindMPN").Range("A1:A768")
For Each FindMPN In ThisWorkbook.Worksheets("FindMPN").Range("A1:A768")
If IsError(FindMPN.Value) = True Then GoTo Here:
On Error GoTo Here:
With Application
matchnumber = .Match(FindMPN, MPN, 0)
prodg = .Index(MPNBase, matchnumber, 0)
End With
FindMPN.Offset(0, 1).Resize(1, 3).Value = Application.Index(prodg, 0, Array(2, 6, 9))
Here:
On Error GoTo 0
Next FindMPN
Application.ScreenUpdating = True
Debug.Print Time
End Sub]
I would like that variable prodg hold the results of all the rows and paste it back once to worksheet not row by row. The reason just to increase the speed of the code. I uploaded a sample file with just 768 rows to find but in actual I have rows of about 900,000 which takes a lot of time. Can someone help me?
[/
Sub testusingranges()
Debug.Print Time
Application.ScreenUpdating = False
Dim MPNBase As Range, MPN As Range, FindMPN As Range
Dim prodg As Variant
Dim matchnumber As Long
Set MPNBase = ThisWorkbook.Worksheets("MPNBase").Range("Table1")
Set MPN = ThisWorkbook.Worksheets("MPNBase").Range("A2:A1000")
Set FindMPN = ThisWorkbook.Worksheets("FindMPN").Range("A1:A768")
For Each FindMPN In ThisWorkbook.Worksheets("FindMPN").Range("A1:A768")
If IsError(FindMPN.Value) = True Then GoTo Here:
On Error GoTo Here:
With Application
matchnumber = .Match(FindMPN, MPN, 0)
prodg = .Index(MPNBase, matchnumber, 0)
End With
FindMPN.Offset(0, 1).Resize(1, 3).Value = Application.Index(prodg, 0, Array(2, 6, 9))
Here:
On Error GoTo 0
Next FindMPN
Application.ScreenUpdating = True
Debug.Print Time
End Sub]