Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Range Question

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Range Question

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
--
Gary''s Student - gsnu200764


"Roger Converse" wrote:

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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,316
Default Range Question

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

--
Kevin Backmann


"Roger Converse" wrote:

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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Range Question

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...
--
HTH...

Jim Thomlinson


"Roger Converse" wrote:

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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Range Question

Appreciate it everyone, it all makes sense.

Thank you.

"Jim Thomlinson" wrote:

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...
--
HTH...

Jim Thomlinson


"Roger Converse" wrote:

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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Range Question N.F[_2_] Excel Discussion (Misc queries) 5 July 28th 07 01:05 AM
Range Question / error 1004: method Range of object Worksheet has failed Paul Excel Programming 3 April 7th 05 02:56 PM
Range question mnewnam[_2_] Excel Programming 0 October 28th 04 07:28 PM
If Range.Name question Otto Moehrbach[_5_] Excel Programming 8 November 30th 03 11:05 PM
Range.Formula and Range question using Excel Automation [email protected] Excel Programming 0 September 19th 03 04:53 AM


All times are GMT +1. The time now is 06:01 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"