vbabeginner92

New Member
Joined
Jul 25, 2018
Messages
13
I am trying to create a macro that will highlight cells already selected. Below is the code I used but that is only working for the active cell. How can I alter the code to highlight all the cells I selected.

Example: Cell C15 is the active cell and cells C15:C20 are selected. When I run my macro, only C15 is highlighted, but I want cells C15:C20 highlighted.

Sub Highlighter()
ActiveCell.Interior.Color = RGB (255,255,0)
End Sub
 

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.
Replace ActiveCell with Selection
 
Upvote 0
Code:
Sub Highlightx()
Dim myRange As Excel.Range
Set myRange = Range("C15:C20")

myRange.Interior.Color = RGB(255, 255, 0)

End Sub
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0
All good thanks for posting back... open a test workbook and havea play and have some fun. Post in a new thread if you have any other questios

jiuk
 
Upvote 0

Forum statistics

Threads
1,214,895
Messages
6,122,128
Members
449,066
Latest member
Andyg666

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