G'day,
I'm hoping someone can help me improve the speed of my script, it is currently working and does the job; however if you start getting above 1000 rows of data, it really takes some time to complete the operation. I can't improve the computers, but I figure someone might have a better and more efficient way of achieving the same task. All of my other code works smoothly and is very efficient, it is just this one piece that really slow.
Concisely, the script works as part of a larger script, and is designed to move data from the "Import Sheet" (Source) to a sheet that houses all the data for further reporting (Destination). In the first column on each sheet is an ID Code and in every column after that are dates that represent item movement. The script goes through each row on the Source Sheet and searches the Destination sheet for the ID Code, if it finds the ID Code it goes to the next blank column in that row and pastes the date from Source Sheet; sometimes each ID Code may have multiple dates, across multiple columns on the source sheet to move across. If the ID code isn't found on the Destination sheet, it goes to the next blank row and does the same as above inputting the dates.
Appreciate any help that may be given
Cheers ANG3L
I'm hoping someone can help me improve the speed of my script, it is currently working and does the job; however if you start getting above 1000 rows of data, it really takes some time to complete the operation. I can't improve the computers, but I figure someone might have a better and more efficient way of achieving the same task. All of my other code works smoothly and is very efficient, it is just this one piece that really slow.
Concisely, the script works as part of a larger script, and is designed to move data from the "Import Sheet" (Source) to a sheet that houses all the data for further reporting (Destination). In the first column on each sheet is an ID Code and in every column after that are dates that represent item movement. The script goes through each row on the Source Sheet and searches the Destination sheet for the ID Code, if it finds the ID Code it goes to the next blank column in that row and pastes the date from Source Sheet; sometimes each ID Code may have multiple dates, across multiple columns on the source sheet to move across. If the ID code isn't found on the Destination sheet, it goes to the next blank row and does the same as above inputting the dates.
Appreciate any help that may be given
Cheers ANG3L
Code:
Set Source = wbCopyTo.Sheets("#Sheet With Imported Data#")
Set Destination = wbCopyTo.Sheets("#Sheet that Imported Data Gets Sorted Into#")
Set DTGDATA = Source.Range("A3")
Set stFnd = Source.Range("A3")
Set n = Source.Range(stFnd, stFnd).End(xlToRight)
With Source
l = 0
ll = 0
For Each r In Source.Range("A3", Source.Range("A3").End(xlDown))
Set rFndCell = Destination.Range("b1:b10000").Find(stFnd, LookIn:=xlValues, LookAt:=xlWhole)
If Not rFndCell Is Nothing Then
rRow = rFndCell.Row
For Each c In Source.Range(stFnd, n)
emptyColumn = Destination.Cells(rRow, Destination.Columns.Count).End(xlToLeft).Column
If emptyColumn > 0 Then
emptyColumn = emptyColumn + 1
End If
yRow = DTGDATA.Row
yCol = DTGDATA.Column + 1
Source.Cells(yRow, yCol).Copy
Destination.Cells(rRow, emptyColumn).PasteSpecial xlPasteValues
l = l + 1
Set DTGDATA = Source.Range("A3").Offset(ll, l)
Next c
Else
Set rFndCell = Destination.Range("b1:b10000").Find("", LookIn:=xlValues, LookAt:=xlWhole)
rRow = rFndCell.Row
For Each c In Source.Range(stFnd, n)
emptyColumn = Destination.Cells(rRow, Destination.Columns.Count).End(xlToLeft).Column
If emptyColumn > 0 Then
emptyColumn = emptyColumn + 1
End If
yRow = DTGDATA.Row
yCol = DTGDATA.Column
Source.Cells(yRow, yCol).Copy
Destination.Cells(rRow, emptyColumn).PasteSpecial xlPasteValues
l = l + 1
Set DTGDATA = Source.Range("A3").Offset(ll, l)
Next c
End If
l = 0
ll = ll + 1
Set stFnd = Source.Range("A3").Offset(ll, 0)
Set DTGDATA = Source.Range("A3").Offset(ll, 0)
Set n = Source.Range(stFnd, stFnd).End(xlToRight).Offset(1, 0)
Next r
End With