Speed up selected cell fill colour macro

Milos

Board Regular
Joined
Aug 28, 2016
Messages
121
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I am unsuccessfully trying to speed up my un-highlight selected cells macro. I have been toying with the code to speed it up as if I mistakenly select an entire row it takes a long time to complete. But I am too useless and have failed to get it working correctly. I have also been trying to insert the 'Do Until' code and putting in a loop.

What I am after is for the macro to search through all of the selected cells and if the cell has no fill colour applied then it will skip to the next selected cell with a fill colour. For all other cells that are filled with colour the macro will apply a colour index = 0.

Here is my faulty code:
Code:
Sub Un_Highlight_Selected_Cells()
   
   Application.ScreenUpdating = False
   Dim Rng As Range, cell As Range
   Set Rng = Selection
   For Each cell In Rng
   If cell.Interior.ColorIndex = xlColorIndexNone Then
   cell.Offset(0, 1).Select
   
Else: cell.Interior.ColorIndex = 0
   Next cell
   
    Application.ScreenUpdating = True
   
End Sub

Any help is appreciated,
Thanks
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hello,

In order to make your life easier ...in your Sheet module ... you could have :

Code:
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
   Selection.Interior.ColorIndex = xlColorIndexNone
   Cancel = True
End Sub

Hope this will help
 
Last edited:
Upvote 0
Thanks James, I was kind of hoping that there was a module based solution so I could store this in my personal modules as a lot of the spreadsheets that I use are password protected. But this is great for all the other spreadsheets!
 
Upvote 0
Hello,

Code:
[COLOR=#333333]Sub Un_Highlight_Selected_Cells()[/COLOR]
   [COLOR=#333333]Selection.Interior.ColorIndex = xlColorIndexNone[/COLOR]
End Sub

HTH
 
Upvote 0
Wow that is so much simpler than my previous code! I do like to take the long route. Thanks heaps James
 
Upvote 0

Forum statistics

Threads
1,224,901
Messages
6,181,639
Members
453,059
Latest member
jkevin

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