I am looking for a way in VBA for Excel that's quicker than arrays for updating dates from data. I have tried using scripting.dictionary but got stuck. Sample data and current code that works are below.
Values for serial are non-unique. Hence currently thinking that these need to be looped over twice for considering each row.
The objective of the code is to set dates1 to be value of dates2 when there is a match on serial and value of boolean1 is 1, then to output this back to the sheet.
There is currently over 125000 rows of data and this is set to increase gradually over next few months.
There should only be one line with unique serial and also having boolean1 of 1.
Currently the code below takes 8 mins on an i7 processor. The main aim is to reduce this time if possible. An index match formula might be quicker, but also looking for other solutions such as dictionaries, collections etc.
Sample input data:
serial boolean1 dates2 dates1
ABC001 0 01/01/19
ABC002 0 02/01/19
ABC003 0 03/01/19
ABC004 0 02/01/19
ABC005 0 02/01/19
ABC001 1 11/01/19
ABC002 1 12/01/19
ABC003 1 13/01/19
ABC004 1 12/01/19
Expected output data:
serial boolean1 dates2 dates1
ABC001 0 01/01/19 11/01/19
ABC002 0 02/01/19 12/01/19
ABC003 0 03/01/19 13/01/19
ABC004 0 02/01/19 12/01/19
ABC005 0 02/01/19
ABC001 1 11/01/19 11/01/19
ABC002 1 12/01/19 12/01/19
ABC003 1 13/01/19 13/01/19
ABC004 1 12/01/19 12/01/19
Current code:
serial() = sheetnm1.Range("serial_nr").Value
boolean1() = sheetnm1.Range("boolean_nr").Value
dates1() = sheetnm1.Range("dates1_nr").Value
dates2() = sheetnm1.Range("dates2_nr").Value
y = 1
For x = 1 To UBound(boolean1, 1)
If boolean1(x, 1) = 1 Then
For y = 1 To UBound(boolean1, 1)
If serial(y, 1) = serial(x, 1) Then
dates1(y, 1) = dates2(x, 1)
End If
Next y
End If
Next x
sheetnm1.Range("dates1_nr") = dates1
