I am running an asset management project in excel. Using a connection with an SQL database I am able to import large numbers of maintenance plans.
Based on what I import, I fill a number of cells with specific short strings, and I additionally paint the interior of the respective cells with one of two colours. Cells that later are populated by the user remain unpainted.
Cells populated using the database data will always be coloured
When I later run a command that populates a large number of cells again, some of these cells may already be populated either by the user or the database. These specific cells must be skipped, and so far I am aware of three possible methods of determining if a cell must be skipped:
- Checking with the database (slow): a poor solution since the cells have already been populated with the database, another run would be overdoing it
- Checking wether the cell is populated:
If not cell.Value = vbNullstring Then
- Checking whether a cell is coloured:
If not cell.Interior.Color = vbRed Then
Now, because in theory the amount of populated cells could be up to half a million or even more, I am wondering about the performance differences between the second and third option
Is there any noticeable difference between checking a cell's value versus a cell's interior colour?
Just extended the code from here: Performance difference between looping range vs looping array
Range tested: A1:A100000
So you have the direct comparison between reading color vs reading array value too.
There seems to be a performance difference indeed. I just checked a cell's value and a cell's interior colour for one hundred million times and there are clear differences:
In other words: checking the values goes ±2.8 times faster (following this single simple experiment).