Seeking to highlight constants in a range of cells

auto.pilot

Well-known Member
Joined
Sep 27, 2007
Messages
719
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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
23,980
VBA Code:
For Each rng In ws.Range("B4:D13").SpecialCells(xlCellTypeConstants)
 

GWteB

Well-known Member
Joined
Sep 10, 2010
Messages
1,295
Office Version
  1. 2013
Platform
  1. Windows
Rich (BB code):
For Each rng In ws.Range("B4:D13").SpecialCells(xlCellTypeConstants)
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,536
Office Version
  1. 365
Platform
  1. Windows
No need for the loop, you can do it like
VBA Code:
   ws.Range("B4:D13").SpecialCells(xlCellTypeConstants).Interior.ColorIndex = 36
 
Solution

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,536
Office Version
  1. 365
Platform
  1. Windows
Glad we could help & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,502
Messages
5,636,694
Members
416,935
Latest member
Atulcp

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
Top