Range Question

  • Thread starter Thread starter Roger Converse
  • Start date Start date
R

Roger Converse

I have the following and am receiving a run time error 1004. Application
defined or Object Defined error.

What am I doing incorrectly?

Worksheets(1).Activate
If CheckBox1.Value = True Then
Set rg1 = Range("A17:F17")
Sheets(1).Range("rg1").Interior.Color = vbYellow
Else

I am trying to select the cells from A17 - F17 and highlight them yellow.

Thank you,
Roger
 
use:

Sheets(1).rg1.Interior.Color = vbYellow

instead of:

Sheets(1).Range("rg1").Interior.Color = vbYellow


You don't need RANGE() because rg1 is already a range
 
You've already declared rng1 as a range and in the line above the ELSE
statement you're using it as a string

change Sheets(1).Range("rg1").Interior.Color = vbYellow

to rg1.Interior.Color = vbYellow
 
Since I see no good reason to set your range object (unless you use it late
on somewhere) you could just use...
Sheets(1).Range("A17:F17").Interior.Color = vbYellow
If you really need the range object then
Set rng1 = Sheets(1).Range("A17:F17")
rng1.Interior.Color = vbYellow

Note that you want to define the sheet when you set the range object and
then you do not need to reference the sheet again. The range object knows
which sheet it's on...
 
Back
Top