Activate range by Offset

mnmhenry

Board Regular
Joined
Mar 28, 2002
Messages
169
Hi all

how do I activte a range by using activecell.offset function....

ie

I want to hilight say A1:G1 to eventually color the cells red.....I know I can just go range A1:G1 activate........ But I first just want to activate A1, run the code using offset command color the cells and deselect....

I dont know how to activate the 7 cells all at once....

Thanks in advance
Mark
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
You can use Offset or Resize to select that range:

Range(ActiveCell, ActiveCell.Offset(0, 6)).Select

or

ActiveCell.Resize(1, 7).Select



Keep in mind you don't need to select the range to manipulate it, shading it red as you said:

Range(ActiveCell, ActiveCell.Offset(0, 6)).Interior.ColorIndex = 3

or

ActiveCell.Resize(1, 7).Interior.ColorIndex = 3
 
Upvote 0
Hi Mark,

try this:

sub OffsetandColor

Range("A1").select
'do whatever you were planning
ActiveCell.Resize(1, 7).Interior.ColorIndex = 3

Range("A1").Select

end sub


HTH, Slink
Oops, Tom already beat me to it!
 
Upvote 0
Thanks Tom & Slink, Woked a treat. I had that method in my mind but could not get the combination right... as for the resize command, I have never sen this before... How does this differ from Offset ?

Thanks again
 
Upvote 0
Hi again Mark,
Offset moves from the active cell a certain number of rows and columns:
activecell.offset(0,4).interior.colorindex = 3
will color the cell that is 4 columns over and 0 rows down.
activecell.resize(1,7).interior.colorindex = 3
will color 1 row and 7 columns over from the active cell.

You can play around with the row and column choices to color (2,7) etc. When using resize, it will color 2 rows and 7 columns.

Slink
 
Upvote 0

Forum statistics

Threads
1,224,882
Messages
6,181,549
Members
453,053
Latest member
ezzat

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