contiguous-ish active range selection?

MsDeth

New Member
Joined
May 8, 2004
Messages
41
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

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hi, does this work for you?

Code:
Sub test()
If ActiveCell = "V" Then _
    ActiveCell.Offset(, -1).Resize(1, 6).Interior.ColorIndex = 19
End Sub
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,818
Members
449,049
Latest member
cybersurfer5000

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