Cell Ranges within sheets

Flue

Board Regular
Joined
Feb 5, 2009
Messages
106
HI all.

Can some explain why this code;
Code:
Range(Cells(FoundCell.Row, 1), Cells(FoundCell.Row, 6)).Interior.ColorIndex = 6
works for the main sheet, but as soon as you want to assign a sheet name (if working with multiple sheets) to it you have to use;
Code:
Sheets("TEST1_15").Range("A" & i & ":F" & i).Interior.ColorIndex = 6

Even this works;
Code:
 Sheets("TEST1_15").Range(Cells(FoundCell.Row, 1)).Interior.ColorIndex = 6
But add that second Cell for the range and it fails.

Any Idea?

Thanks.

Brian
 
This will work

Code:
Sheets("TEST1_15").Range(Sheets("TEST1_15").Cells(i, 1), Sheets("TEST1_15").Cells(i, 5)).Interior.ColorIndex = 6
 
Upvote 0

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Kind of making a little sense.

If using this:
Code:
Sheets("TEST1_15").Range(Cells(i, 1), Cells(i, 5)).Interior.ColorIndex = 6
from a module it works just fine...once the code is plugged in the sheet("LIVE1_15") VB editor, it fails.

I knew that was an issue, but it's been a while so I tend to forget...Most of my code(s) reside in modules and not on the sheets. I guess that kind of makes sense.
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,833
Members
452,947
Latest member
Gerry_F

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