Seeking to highlight constants in a range of cells

auto.pilot

Well-known Member
Joined
Sep 27, 2007
Messages
734
Office Version
  1. 365
Platform
  1. Windows
I have the following which highlights all cells on the active sheet that are Type Constants. Instead, I'd like to specify a range of cells (B4:D13) rather than the whole sheet.

How can I do this?

Also... I would like a VBA solution, not conditional formatting.


VBA Code:
Sub NonFormulaCells()

Dim ws As Worksheet
Dim rng As Range
Set ws = ActiveSheet

For Each rng In ws.Cells.SpecialCells(xlCellTypeConstants)

rng.Interior.ColorIndex = 36
Next rng
End Sub

Thanks in advance.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Rich (BB code):
For Each rng In ws.Range("B4:D13").SpecialCells(xlCellTypeConstants)
 
Upvote 0
No need for the loop, you can do it like
VBA Code:
   ws.Range("B4:D13").SpecialCells(xlCellTypeConstants).Interior.ColorIndex = 36
 
Upvote 0
Solution
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,559
Messages
6,120,194
Members
448,951
Latest member
jennlynn

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