contiguous-ish active range selection?

MsDeth

New Member
Joined
May 8, 2004
Messages
37
I'm sure this has been asked/answered before, but had no luck searching the forum.

Is there a way to condense this:
Code:
If ActiveCell = "V" Then
    With ActiveCell.Interior: .colorindex = 19
    With ActiveCell.Offset(0, -1): .Interior.colorindex = 19
    With ActiveCell.Offset(0, 1): .Interior.colorindex = 19
   With ActiveCell.Offset(0, 2): .Interior.colorindex = 19
    With ActiveCell.Offset(0, 3): .Interior.colorindex = 19
    With ActiveCell.Offset(0, 4): .Interior.colorindex = 19
'etc., etc.
Into something along the lines of
Code:
 If ActiveCell = "V" Then
With ActiveCell.Interior AND ActiveCell.Offset(0,-1) _
AND etc., etc.: .Interior.colorindex = 19
or
Code:
 If If ActiveCell = "V" Then
With ActiveCell.Offset (0,-1) THROUGH ActiveCell.Offset(0,4) _
:.Interior.colorindex = 19


I realize the "AND" or "THROUGH" won't do the trick, just trying to make it obvious what I'm trying to accomplish...I'd like to "condense" the code a bit.
Any help appreciated!

-MsDeth
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,958
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Hi, does this work for you?

Code:
Sub test()
If ActiveCell = "V" Then _
    ActiveCell.Offset(, -1).Resize(1, 6).Interior.ColorIndex = 19
End Sub
 

MsDeth

New Member
Joined
May 8, 2004
Messages
37
Hi, does this work for you?

Code:
Sub test()
If ActiveCell = "V" Then _
    ActiveCell.Offset(, -1).Resize(1, 6).Interior.ColorIndex = 19
End Sub

Indeed, it works perfectly. I'd never encountered ".resize"; glad to learn about it.
Thanx!

-Ms.Deth
 

Forum statistics

Threads
1,175,849
Messages
5,899,841
Members
434,800
Latest member
gazzal

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