How to avoid cell SELECTION but still format cells to speed up the macro running speed

BertyBerts

New Member
Joined
May 5, 2018
Messages
2
Hi,

I have the following code that checks for a condition in the range, and ifit is a ‘1’ then it select some cells and formats them (by changing theinterior colour, interior.ThemeColor and Font.ThemeColor).

The problem is that, as the program loops through so many cells, itselects many – prior to making the changes – and the macro is very very slow.

I’m looking either (1) for a way to avoid the cell selection* but use thesame basic principle or (2) alternative way all together.

* I’ve found that I can do StatusMarker.Offset(0, 6).Interior.Color =5296274 but this method doesn’t work with the ThemeColour requirements.

The macro’s far too slow and any help will be really appreciated – codebelow:

Code:
'Count Number of Green Ticks and Record
'If Green Tick in Completed Column)Green Each Process Stream DescriptionCell/Grey Time Columns 
'1st Process Stream
'Set Counters
y = 0
z = 0
For Each StatusMarker In StatusTimeSpan
If StatusMarker.Offset(0, 5) = 1 Then
y = y + 1 'MsgBox x
StatusMarker.Offset(0, 6).Select
Selection.Interior.Color = 5296274
Range(StatusMarker.Offset(0, 2), StatusMarker.Offset(0, 4)).Select
Selection.Interior.ThemeColor = xlThemeColorDark2
Selection.Font.ThemeColor = xlThemeColorDark2
End If
Next StatusMarker 'MsgBox x
Sheets("Data").Range("B8").Value = y
 
Last edited by a moderator:

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Almost any time there is .Select and then Selection., you can remove both and it will do the same thing......ALMOST any time.

But you're saying that this:

Code:
[FONT=Calibri][SIZE=3][COLOR=#000000]Range(StatusMarker.Offset(0, 2), StatusMarker.Offset(0, 4)).Select
Selection.Interior.ThemeColor = xlThemeColorDark2[/COLOR][/SIZE][/FONT]

works, but this:

Code:
[FONT=Calibri][SIZE=3][COLOR=#000000]Range(StatusMarker.Offset(0, 2), StatusMarker.Offset(0, 4)).Interior.ThemeColor = xlThemeColorDark2[/COLOR][/SIZE][/FONT]

doesn't?

I'm not in a place to test it right now, but I can't imagine it wouldn't work. If it bugs out, what is the error that it specifies? Or does it just run through but not do anything?
 
Upvote 0
Hi. Thanks for your really quick response.

It works with .interior.colour but not with with .interior.theme.colour for some reason.

Cheers, BertyBerts
 
Upvote 0
I've never used it, so I don't know but according to your first post, it should be ThemeColor...not Theme.Color...(no dot). Is that right? And could that be why it's not working? Like I said, I don't know...never used it, just noticed that difference between Post 1 and Post 3
 
Upvote 0
How about
Code:
StatusMarker.Offset(0, 6).Interior.Color = 5296274
With Range(StatusMarker.Offset(0, 2), StatusMarker.Offset(0, 4))
   .Interior.ThemeColor = xlThemeColorDark2
   .Font.ThemeColor = xlThemeColorDark2
End With
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top