Performance difference between checking a cell's interior colour vs. its valueHow do you test running time of VBA code?Performance difference between looping range vs looping arrayFastest way to transfer large amounts of data between worksheetsCopy data from one sheet to another based on some condition in the third sheet? Excel Crashes sometimes when I run this codeIs there a performance difference between i++ and ++i in C?Is there a performance difference between i++ and ++i in C++?Is there a performance difference between a for loop and a for-each loop?What is the difference between call and apply?Get difference between two listsPerformance differences between debug and release buildsWhat is the difference between parseInt() and Number()?Fastest way to check if a value exist in a listWhat is the difference between .text, .value, and .value2?Copy one static cell's value onto a second dynamic cell (with specific row criteria) based on a third cell's value
Earliest evidence of objects intended for future archaeologists?
What are the ramifications of this change to upcasting spells?
Does the Green Flame-Blade cantrip work with the Zephyr Strike spell?
Is there a commercial liquid with refractive index greater than n=2?
How can I get rid of this Lazy Spool, or otherwise improve this query's performance?
Do living authors still get paid royalties for their old work?
Arduino- Duty Cycle Changing When Frequency Is Increasing
How did Apollo 15's depressurization work?
My two team members in a remote location don't get along with each other; how can I improve working relations?
Gofer work in exchange for Letter of Recommendation
Why is su world executable?
Do predators tend to have vertical slit pupils versus horizontal for prey animals?
Nuclear decay triggers
How does the Saturn V Dynamic Test Stand work?
Can my Boyfriend, who lives in the UK and has a Polish passport, visit me in the USA?
TechSupport Issue ID#812
Why don't sharp and flat root note chords seem to be present in much guitar music?
Has there ever been a truly bilingual country prior to the contemporary period?
Is this kind of description not recommended?
Default camera device to show screen instead of physical camera
How to think about joining a company whose business I do not understand?
Changing a TGV booking
Cheap storage lockers in Tromsø, Norway
Why doesn't mathematics collapse down, even though humans quite often make mistakes in their proofs?
Performance difference between checking a cell's interior colour vs. its value
How do you test running time of VBA code?Performance difference between looping range vs looping arrayFastest way to transfer large amounts of data between worksheetsCopy data from one sheet to another based on some condition in the third sheet? Excel Crashes sometimes when I run this codeIs there a performance difference between i++ and ++i in C?Is there a performance difference between i++ and ++i in C++?Is there a performance difference between a for loop and a for-each loop?What is the difference between call and apply?Get difference between two listsPerformance differences between debug and release buildsWhat is the difference between parseInt() and Number()?Fastest way to check if a value exist in a listWhat is the difference between .text, .value, and .value2?Copy one static cell's value onto a second dynamic cell (with specific row criteria) based on a third cell's value
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
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?
excel vba performance
|
show 7 more comments
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?
excel vba performance
Why don't you just run both on the same amount of cells and stop the time with a timer? Then you know it. • Actually that is what anyone else here would need to do too. See How do you test running time of VBA code?
– Pᴇʜ
Mar 27 at 14:57
Because I am under the impression some of us here know a lot more about computing than I do, and I would like to understand why this difference, if there is any, exists
– Tim Stack
Mar 27 at 14:59
I suggest to read the data into an array and then test the values in the array forvbNullString
. This should be a alot faster than testing each cell. Actually you can only do this with.Value
but not with.Interior.Color
.
– Pᴇʜ
Mar 27 at 15:01
I'm afraid I can't do that, it's a tad more complicated than that. Before a cell is checked, values in other columns need to be found and compared with other data.
– Tim Stack
Mar 27 at 15:03
2
I've been programming in Excel for years, but know almost nothing about its internals, at last nothing that would allow me to predict Value vs Color performance. I suspect that's true for many others who answer here too. As @PEH notes, a quick test would provide a pretty reliable answer to your question.
– Tim Williams
Mar 27 at 15:19
|
show 7 more comments
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?
excel vba performance
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?
excel vba performance
excel vba performance
asked Mar 27 at 14:39
Tim StackTim Stack
2,1211 gold badge5 silver badges26 bronze badges
2,1211 gold badge5 silver badges26 bronze badges
Why don't you just run both on the same amount of cells and stop the time with a timer? Then you know it. • Actually that is what anyone else here would need to do too. See How do you test running time of VBA code?
– Pᴇʜ
Mar 27 at 14:57
Because I am under the impression some of us here know a lot more about computing than I do, and I would like to understand why this difference, if there is any, exists
– Tim Stack
Mar 27 at 14:59
I suggest to read the data into an array and then test the values in the array forvbNullString
. This should be a alot faster than testing each cell. Actually you can only do this with.Value
but not with.Interior.Color
.
– Pᴇʜ
Mar 27 at 15:01
I'm afraid I can't do that, it's a tad more complicated than that. Before a cell is checked, values in other columns need to be found and compared with other data.
– Tim Stack
Mar 27 at 15:03
2
I've been programming in Excel for years, but know almost nothing about its internals, at last nothing that would allow me to predict Value vs Color performance. I suspect that's true for many others who answer here too. As @PEH notes, a quick test would provide a pretty reliable answer to your question.
– Tim Williams
Mar 27 at 15:19
|
show 7 more comments
Why don't you just run both on the same amount of cells and stop the time with a timer? Then you know it. • Actually that is what anyone else here would need to do too. See How do you test running time of VBA code?
– Pᴇʜ
Mar 27 at 14:57
Because I am under the impression some of us here know a lot more about computing than I do, and I would like to understand why this difference, if there is any, exists
– Tim Stack
Mar 27 at 14:59
I suggest to read the data into an array and then test the values in the array forvbNullString
. This should be a alot faster than testing each cell. Actually you can only do this with.Value
but not with.Interior.Color
.
– Pᴇʜ
Mar 27 at 15:01
I'm afraid I can't do that, it's a tad more complicated than that. Before a cell is checked, values in other columns need to be found and compared with other data.
– Tim Stack
Mar 27 at 15:03
2
I've been programming in Excel for years, but know almost nothing about its internals, at last nothing that would allow me to predict Value vs Color performance. I suspect that's true for many others who answer here too. As @PEH notes, a quick test would provide a pretty reliable answer to your question.
– Tim Williams
Mar 27 at 15:19
Why don't you just run both on the same amount of cells and stop the time with a timer? Then you know it. • Actually that is what anyone else here would need to do too. See How do you test running time of VBA code?
– Pᴇʜ
Mar 27 at 14:57
Why don't you just run both on the same amount of cells and stop the time with a timer? Then you know it. • Actually that is what anyone else here would need to do too. See How do you test running time of VBA code?
– Pᴇʜ
Mar 27 at 14:57
Because I am under the impression some of us here know a lot more about computing than I do, and I would like to understand why this difference, if there is any, exists
– Tim Stack
Mar 27 at 14:59
Because I am under the impression some of us here know a lot more about computing than I do, and I would like to understand why this difference, if there is any, exists
– Tim Stack
Mar 27 at 14:59
I suggest to read the data into an array and then test the values in the array for
vbNullString
. This should be a alot faster than testing each cell. Actually you can only do this with .Value
but not with .Interior.Color
.– Pᴇʜ
Mar 27 at 15:01
I suggest to read the data into an array and then test the values in the array for
vbNullString
. This should be a alot faster than testing each cell. Actually you can only do this with .Value
but not with .Interior.Color
.– Pᴇʜ
Mar 27 at 15:01
I'm afraid I can't do that, it's a tad more complicated than that. Before a cell is checked, values in other columns need to be found and compared with other data.
– Tim Stack
Mar 27 at 15:03
I'm afraid I can't do that, it's a tad more complicated than that. Before a cell is checked, values in other columns need to be found and compared with other data.
– Tim Stack
Mar 27 at 15:03
2
2
I've been programming in Excel for years, but know almost nothing about its internals, at last nothing that would allow me to predict Value vs Color performance. I suspect that's true for many others who answer here too. As @PEH notes, a quick test would provide a pretty reliable answer to your question.
– Tim Williams
Mar 27 at 15:19
I've been programming in Excel for years, but know almost nothing about its internals, at last nothing that would allow me to predict Value vs Color performance. I suspect that's true for many others who answer here too. As @PEH notes, a quick test would provide a pretty reliable answer to your question.
– Tim Williams
Mar 27 at 15:19
|
show 7 more comments
2 Answers
2
active
oldest
votes
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:
Checking the value : 456 seconds
Checking the colour: 1281 seconds
In other words: checking the values goes ±2.8 times faster (following this single simple experiment).
Superb, thank you very much for the time and effort
– Tim Stack
Mar 27 at 15:53
add a comment |
Just extended the code from here: Performance difference between looping range vs looping array
Range tested: A1:A100000
Read/Write Cell = 15,765625 seconds
Read/Write Array = 0,203125 seconds
Read Cell = 0,37109375 seconds
Read Array = 0,0234375 seconds
Read Interior Color = 1,421875 seconds
So you have the direct comparison between reading color vs reading array value too.
Option Explicit
Const strRANGE_ADDRESS As String = "A1:A100000"
Sub LoopRangeReadWrite()
Dim r As Range
Dim lStart As Double
Dim lEnd As Double
lStart = Timer
For Each r In Range(strRANGE_ADDRESS)
r.Value = r.Value + 1
Next r
lEnd = Timer
Debug.Print "Read/Write Cell = " & (lEnd - lStart) & " seconds"
End Sub
Sub LoopArrayAddOne()
Dim varArray As Variant
Dim var As Variant
Dim lStart As Double
Dim lEnd As Double
lStart = Timer
varArray = Range(strRANGE_ADDRESS).Value
For Each var In varArray
var = var + 1
Next var
Range(strRANGE_ADDRESS).Value = varArray
lEnd = Timer
Debug.Print "Read/Write Array = " & (lEnd - lStart) & " seconds"
End Sub
Sub LoopRangeReadColor()
Dim r As Range
Dim lStart As Double
Dim lEnd As Double
Dim a As Long
lStart = Timer
For Each r In Range(strRANGE_ADDRESS)
a = r.Interior.Color
Next r
lEnd = Timer
Debug.Print "Read Interior Color = " & (lEnd - lStart) & " seconds"
End Sub
Sub LoopRangeReadValue()
Dim r As Range
Dim lStart As Double
Dim lEnd As Double
Dim a As Variant
lStart = Timer
For Each r In Range(strRANGE_ADDRESS)
a = r.Value
Next r
lEnd = Timer
Debug.Print "Read Cell = " & (lEnd - lStart) & " seconds"
End Sub
Sub LoopArrayValue()
Dim varArray As Variant
Dim var As Variant
Dim lStart As Double
Dim lEnd As Double
lStart = Timer
varArray = Range(strRANGE_ADDRESS).Value
For Each var In varArray
var = var + 1
Next var
lEnd = Timer
Debug.Print "Read Array = " & (lEnd - lStart) & " seconds"
End Sub
Awesome, definitely shows the performance boost arrays will give me. Cheers
– Tim Stack
Mar 27 at 17:15
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55379925%2fperformance-difference-between-checking-a-cells-interior-colour-vs-its-value%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
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:
Checking the value : 456 seconds
Checking the colour: 1281 seconds
In other words: checking the values goes ±2.8 times faster (following this single simple experiment).
Superb, thank you very much for the time and effort
– Tim Stack
Mar 27 at 15:53
add a comment |
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:
Checking the value : 456 seconds
Checking the colour: 1281 seconds
In other words: checking the values goes ±2.8 times faster (following this single simple experiment).
Superb, thank you very much for the time and effort
– Tim Stack
Mar 27 at 15:53
add a comment |
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:
Checking the value : 456 seconds
Checking the colour: 1281 seconds
In other words: checking the values goes ±2.8 times faster (following this single simple experiment).
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:
Checking the value : 456 seconds
Checking the colour: 1281 seconds
In other words: checking the values goes ±2.8 times faster (following this single simple experiment).
answered Mar 27 at 15:49
DominiqueDominique
2,9206 gold badges22 silver badges49 bronze badges
2,9206 gold badges22 silver badges49 bronze badges
Superb, thank you very much for the time and effort
– Tim Stack
Mar 27 at 15:53
add a comment |
Superb, thank you very much for the time and effort
– Tim Stack
Mar 27 at 15:53
Superb, thank you very much for the time and effort
– Tim Stack
Mar 27 at 15:53
Superb, thank you very much for the time and effort
– Tim Stack
Mar 27 at 15:53
add a comment |
Just extended the code from here: Performance difference between looping range vs looping array
Range tested: A1:A100000
Read/Write Cell = 15,765625 seconds
Read/Write Array = 0,203125 seconds
Read Cell = 0,37109375 seconds
Read Array = 0,0234375 seconds
Read Interior Color = 1,421875 seconds
So you have the direct comparison between reading color vs reading array value too.
Option Explicit
Const strRANGE_ADDRESS As String = "A1:A100000"
Sub LoopRangeReadWrite()
Dim r As Range
Dim lStart As Double
Dim lEnd As Double
lStart = Timer
For Each r In Range(strRANGE_ADDRESS)
r.Value = r.Value + 1
Next r
lEnd = Timer
Debug.Print "Read/Write Cell = " & (lEnd - lStart) & " seconds"
End Sub
Sub LoopArrayAddOne()
Dim varArray As Variant
Dim var As Variant
Dim lStart As Double
Dim lEnd As Double
lStart = Timer
varArray = Range(strRANGE_ADDRESS).Value
For Each var In varArray
var = var + 1
Next var
Range(strRANGE_ADDRESS).Value = varArray
lEnd = Timer
Debug.Print "Read/Write Array = " & (lEnd - lStart) & " seconds"
End Sub
Sub LoopRangeReadColor()
Dim r As Range
Dim lStart As Double
Dim lEnd As Double
Dim a As Long
lStart = Timer
For Each r In Range(strRANGE_ADDRESS)
a = r.Interior.Color
Next r
lEnd = Timer
Debug.Print "Read Interior Color = " & (lEnd - lStart) & " seconds"
End Sub
Sub LoopRangeReadValue()
Dim r As Range
Dim lStart As Double
Dim lEnd As Double
Dim a As Variant
lStart = Timer
For Each r In Range(strRANGE_ADDRESS)
a = r.Value
Next r
lEnd = Timer
Debug.Print "Read Cell = " & (lEnd - lStart) & " seconds"
End Sub
Sub LoopArrayValue()
Dim varArray As Variant
Dim var As Variant
Dim lStart As Double
Dim lEnd As Double
lStart = Timer
varArray = Range(strRANGE_ADDRESS).Value
For Each var In varArray
var = var + 1
Next var
lEnd = Timer
Debug.Print "Read Array = " & (lEnd - lStart) & " seconds"
End Sub
Awesome, definitely shows the performance boost arrays will give me. Cheers
– Tim Stack
Mar 27 at 17:15
add a comment |
Just extended the code from here: Performance difference between looping range vs looping array
Range tested: A1:A100000
Read/Write Cell = 15,765625 seconds
Read/Write Array = 0,203125 seconds
Read Cell = 0,37109375 seconds
Read Array = 0,0234375 seconds
Read Interior Color = 1,421875 seconds
So you have the direct comparison between reading color vs reading array value too.
Option Explicit
Const strRANGE_ADDRESS As String = "A1:A100000"
Sub LoopRangeReadWrite()
Dim r As Range
Dim lStart As Double
Dim lEnd As Double
lStart = Timer
For Each r In Range(strRANGE_ADDRESS)
r.Value = r.Value + 1
Next r
lEnd = Timer
Debug.Print "Read/Write Cell = " & (lEnd - lStart) & " seconds"
End Sub
Sub LoopArrayAddOne()
Dim varArray As Variant
Dim var As Variant
Dim lStart As Double
Dim lEnd As Double
lStart = Timer
varArray = Range(strRANGE_ADDRESS).Value
For Each var In varArray
var = var + 1
Next var
Range(strRANGE_ADDRESS).Value = varArray
lEnd = Timer
Debug.Print "Read/Write Array = " & (lEnd - lStart) & " seconds"
End Sub
Sub LoopRangeReadColor()
Dim r As Range
Dim lStart As Double
Dim lEnd As Double
Dim a As Long
lStart = Timer
For Each r In Range(strRANGE_ADDRESS)
a = r.Interior.Color
Next r
lEnd = Timer
Debug.Print "Read Interior Color = " & (lEnd - lStart) & " seconds"
End Sub
Sub LoopRangeReadValue()
Dim r As Range
Dim lStart As Double
Dim lEnd As Double
Dim a As Variant
lStart = Timer
For Each r In Range(strRANGE_ADDRESS)
a = r.Value
Next r
lEnd = Timer
Debug.Print "Read Cell = " & (lEnd - lStart) & " seconds"
End Sub
Sub LoopArrayValue()
Dim varArray As Variant
Dim var As Variant
Dim lStart As Double
Dim lEnd As Double
lStart = Timer
varArray = Range(strRANGE_ADDRESS).Value
For Each var In varArray
var = var + 1
Next var
lEnd = Timer
Debug.Print "Read Array = " & (lEnd - lStart) & " seconds"
End Sub
Awesome, definitely shows the performance boost arrays will give me. Cheers
– Tim Stack
Mar 27 at 17:15
add a comment |
Just extended the code from here: Performance difference between looping range vs looping array
Range tested: A1:A100000
Read/Write Cell = 15,765625 seconds
Read/Write Array = 0,203125 seconds
Read Cell = 0,37109375 seconds
Read Array = 0,0234375 seconds
Read Interior Color = 1,421875 seconds
So you have the direct comparison between reading color vs reading array value too.
Option Explicit
Const strRANGE_ADDRESS As String = "A1:A100000"
Sub LoopRangeReadWrite()
Dim r As Range
Dim lStart As Double
Dim lEnd As Double
lStart = Timer
For Each r In Range(strRANGE_ADDRESS)
r.Value = r.Value + 1
Next r
lEnd = Timer
Debug.Print "Read/Write Cell = " & (lEnd - lStart) & " seconds"
End Sub
Sub LoopArrayAddOne()
Dim varArray As Variant
Dim var As Variant
Dim lStart As Double
Dim lEnd As Double
lStart = Timer
varArray = Range(strRANGE_ADDRESS).Value
For Each var In varArray
var = var + 1
Next var
Range(strRANGE_ADDRESS).Value = varArray
lEnd = Timer
Debug.Print "Read/Write Array = " & (lEnd - lStart) & " seconds"
End Sub
Sub LoopRangeReadColor()
Dim r As Range
Dim lStart As Double
Dim lEnd As Double
Dim a As Long
lStart = Timer
For Each r In Range(strRANGE_ADDRESS)
a = r.Interior.Color
Next r
lEnd = Timer
Debug.Print "Read Interior Color = " & (lEnd - lStart) & " seconds"
End Sub
Sub LoopRangeReadValue()
Dim r As Range
Dim lStart As Double
Dim lEnd As Double
Dim a As Variant
lStart = Timer
For Each r In Range(strRANGE_ADDRESS)
a = r.Value
Next r
lEnd = Timer
Debug.Print "Read Cell = " & (lEnd - lStart) & " seconds"
End Sub
Sub LoopArrayValue()
Dim varArray As Variant
Dim var As Variant
Dim lStart As Double
Dim lEnd As Double
lStart = Timer
varArray = Range(strRANGE_ADDRESS).Value
For Each var In varArray
var = var + 1
Next var
lEnd = Timer
Debug.Print "Read Array = " & (lEnd - lStart) & " seconds"
End Sub
Just extended the code from here: Performance difference between looping range vs looping array
Range tested: A1:A100000
Read/Write Cell = 15,765625 seconds
Read/Write Array = 0,203125 seconds
Read Cell = 0,37109375 seconds
Read Array = 0,0234375 seconds
Read Interior Color = 1,421875 seconds
So you have the direct comparison between reading color vs reading array value too.
Option Explicit
Const strRANGE_ADDRESS As String = "A1:A100000"
Sub LoopRangeReadWrite()
Dim r As Range
Dim lStart As Double
Dim lEnd As Double
lStart = Timer
For Each r In Range(strRANGE_ADDRESS)
r.Value = r.Value + 1
Next r
lEnd = Timer
Debug.Print "Read/Write Cell = " & (lEnd - lStart) & " seconds"
End Sub
Sub LoopArrayAddOne()
Dim varArray As Variant
Dim var As Variant
Dim lStart As Double
Dim lEnd As Double
lStart = Timer
varArray = Range(strRANGE_ADDRESS).Value
For Each var In varArray
var = var + 1
Next var
Range(strRANGE_ADDRESS).Value = varArray
lEnd = Timer
Debug.Print "Read/Write Array = " & (lEnd - lStart) & " seconds"
End Sub
Sub LoopRangeReadColor()
Dim r As Range
Dim lStart As Double
Dim lEnd As Double
Dim a As Long
lStart = Timer
For Each r In Range(strRANGE_ADDRESS)
a = r.Interior.Color
Next r
lEnd = Timer
Debug.Print "Read Interior Color = " & (lEnd - lStart) & " seconds"
End Sub
Sub LoopRangeReadValue()
Dim r As Range
Dim lStart As Double
Dim lEnd As Double
Dim a As Variant
lStart = Timer
For Each r In Range(strRANGE_ADDRESS)
a = r.Value
Next r
lEnd = Timer
Debug.Print "Read Cell = " & (lEnd - lStart) & " seconds"
End Sub
Sub LoopArrayValue()
Dim varArray As Variant
Dim var As Variant
Dim lStart As Double
Dim lEnd As Double
lStart = Timer
varArray = Range(strRANGE_ADDRESS).Value
For Each var In varArray
var = var + 1
Next var
lEnd = Timer
Debug.Print "Read Array = " & (lEnd - lStart) & " seconds"
End Sub
answered Mar 27 at 16:12
PᴇʜPᴇʜ
31.3k6 gold badges30 silver badges56 bronze badges
31.3k6 gold badges30 silver badges56 bronze badges
Awesome, definitely shows the performance boost arrays will give me. Cheers
– Tim Stack
Mar 27 at 17:15
add a comment |
Awesome, definitely shows the performance boost arrays will give me. Cheers
– Tim Stack
Mar 27 at 17:15
Awesome, definitely shows the performance boost arrays will give me. Cheers
– Tim Stack
Mar 27 at 17:15
Awesome, definitely shows the performance boost arrays will give me. Cheers
– Tim Stack
Mar 27 at 17:15
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55379925%2fperformance-difference-between-checking-a-cells-interior-colour-vs-its-value%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Why don't you just run both on the same amount of cells and stop the time with a timer? Then you know it. • Actually that is what anyone else here would need to do too. See How do you test running time of VBA code?
– Pᴇʜ
Mar 27 at 14:57
Because I am under the impression some of us here know a lot more about computing than I do, and I would like to understand why this difference, if there is any, exists
– Tim Stack
Mar 27 at 14:59
I suggest to read the data into an array and then test the values in the array for
vbNullString
. This should be a alot faster than testing each cell. Actually you can only do this with.Value
but not with.Interior.Color
.– Pᴇʜ
Mar 27 at 15:01
I'm afraid I can't do that, it's a tad more complicated than that. Before a cell is checked, values in other columns need to be found and compared with other data.
– Tim Stack
Mar 27 at 15:03
2
I've been programming in Excel for years, but know almost nothing about its internals, at last nothing that would allow me to predict Value vs Color performance. I suspect that's true for many others who answer here too. As @PEH notes, a quick test would provide a pretty reliable answer to your question.
– Tim Williams
Mar 27 at 15:19