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
 

Some videos you may like

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
 

Watch MrExcel Video

Forum statistics

Threads
1,111,699
Messages
5,541,271
Members
410,543
Latest member
ExcelGlenn
Top