Can "target.row" be used to select a range of cells instead of just one?

bovinda

Board Regular
Joined
Jun 11, 2005
Messages
87
I have a script that changes font color in a bunch of cells (~30) in the same row. Right now, I'm having to enter

Me.Cells(Target.Row, "C").Font.ColorIndex = myColor
Me.Cells(Target.Row, "E").Font.ColorIndex = myColor
Me.Cells(Target.Row, "F").Font.ColorIndex = myColor
Me.Cells(Target.Row, "G").Font.ColorIndex = myColor
Me.Cells(Target.Row, "H").Font.ColorIndex = myColor...


...etc., etc. for each cell I want affected. Is there a way to specify a range of cells? Like this:

Me.Cells(Target.Row, "C-H").Font.ColorIndex = myColor

So that cells C through H are affected by the change? It would save a lot of typing and cut and pasting!

Thanks for any and all suggestions!
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
40,369
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
Code:
Me.Cells(Target.Row, "C").Resize(,6).Font.ColorIndex = myColor
should do it.
 
Upvote 0

bovinda

Board Regular
Joined
Jun 11, 2005
Messages
87
See, that's what makes the intarweb awesome, because I never would have figured that out in a million years on my own! That's exactly what I was looking for. Thanks Rory! :)
 
Upvote 0

Forum statistics

Threads
1,190,874
Messages
5,983,345
Members
439,840
Latest member
billy1989

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