Thank you in advance for your assistance.
I am running a macro where I have a list of unique records in worksheet "Sheet2" and it will search for these entries in Worksheet "PO_Details" and once it finds the details it will add these fields in "Sheet2" and append to values. So result could be like this:
A; B; C etc depending on the number of records in PO details
My PO_details sheet has 8700 records
My Sheet2 has 6700 unique records
The macro works fine but the only concern is when I run this code it takes about 10 minutes to run. I fear the performance will reduce when the unique records increase to a higher number.
Is there anything I need to do to optimize this code
I am a beginner at this and would appreciate any help :)
Sub Macro3()
' Keyboard Shortcut: Ctrl+u
Dim PO_Name As String
Dim Finalrow As Integer
Dim i As Integer
Dim fValue As String
Dim Tmp As String
Dim x As Integer
Dim fValue1 As String
Dim Tmp1 As String
Dim fValue2 As String
Dim Tmp2 As String
Dim fValue3 As String
Dim Tmp3 As String
Sheets("Sheet2").Range("b2:f20000").ClearContents
Finalrow = Sheets("PO_Details").Range("H30000").End(xlUp).Row
Finalrow_unique = Sheets("Sheet2").Range("a30000").End(xlUp).Row
For x = 2 To Finalrow_unique
PO_Name = Sheets("Sheet2").Range("a" & x).Value
fValue = " "
fValue1 = " "
fValue2 = " "
fValue3 = " "
For i = 2 To Finalrow
If Sheets("PO_Details").Range("h" & i) = PO_Name Then
'Cells(i, 1) = PO_Name Then
Tmp = Sheets("PO_Details").Range("c" & i).Value
fValue = fValue & ";" & Tmp
Tmp1 = Sheets("PO_Details").Range("d" & i).Value
fValue1 = fValue1 & ";" & Tmp1
Tmp2 = Sheets("PO_Details").Range("b" & i).Value
fValue2 = fValue2 & ";" & Tmp2
Tmp3 = Sheets("PO_Details").Range("e" & i).Value
fValue3 = fValue3 & ";" & Tmp3
End If
Next i
Sheets("sheet2").Range("b" & x) = fValue
Sheets("sheet2").Range("c" & x) = fValue1
Sheets("sheet2").Range("d" & x) = fValue2
Sheets("sheet2").Range("e" & x) = fValue3
Next x
End Sub