PC Review


Reply
Thread Tools Rate Thread

absolute relative reference

 
 
=?Utf-8?B?U2ViYXN0aWVu?=
Guest
Posts: n/a
 
      11th Jul 2007
Good day,

Situation:

I am having a macro in "sheet_1" that is doing a whole bunch of operations.
The macro uses a combination of absolute references such as:

Cells(1, "C") = ...

as well as relative references such as:

Range("B1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 1).Select

My problem:

When I need the macro to execute an operation in the next sheet of my
workbook "sheet_2", I write something as simple as:

Sheets("sheet_2").Select
Range("A3:A200").Select

but I have an error message at the second line "Range("A3:A200").Select". I
have never seen this kind of error before. My second line must be written as

Sheets("sheet_2").Range("A2:K2").Select

Usually, When I select a sheet, I do not need to "re-select" it in each line
of the macro, but for this one, I am obliged to do so and it gets quite
annoying.

I think there is a problem of reference (absolute vs relative). Or maybe my
macro is dedicated to sheet_1 only? If this is the case, how do I make it
valid for the whole workbook? In any case, please help!

--
Thanks
Sebastien
 
Reply With Quote
 
 
 
 
=?Utf-8?B?VmVyZ2VsIEFkcmlhbm8=?=
Guest
Posts: n/a
 
      11th Jul 2007
Sebastien,

Perhaps your code is inside a worksheet module? If so, it would explain why
you need to qualify the Range selection. If you don't qualify it, Excel
would attempt to select the range that exists in the worksheet where the code
is. But because that worksheet is no longer the active one, you get the
error. To avoid the error, you will need to move your Sub to a module.


--
Hope that helps.

Vergel Adriano


"Sebastien" wrote:

> Good day,
>
> Situation:
>
> I am having a macro in "sheet_1" that is doing a whole bunch of operations.
> The macro uses a combination of absolute references such as:
>
> Cells(1, "C") = ...
>
> as well as relative references such as:
>
> Range("B1").Select
> Selection.End(xlDown).Select
> ActiveCell.Offset(1, 1).Select
>
> My problem:
>
> When I need the macro to execute an operation in the next sheet of my
> workbook "sheet_2", I write something as simple as:
>
> Sheets("sheet_2").Select
> Range("A3:A200").Select
>
> but I have an error message at the second line "Range("A3:A200").Select". I
> have never seen this kind of error before. My second line must be written as
>
> Sheets("sheet_2").Range("A2:K2").Select
>
> Usually, When I select a sheet, I do not need to "re-select" it in each line
> of the macro, but for this one, I am obliged to do so and it gets quite
> annoying.
>
> I think there is a problem of reference (absolute vs relative). Or maybe my
> macro is dedicated to sheet_1 only? If this is the case, how do I make it
> valid for the whole workbook? In any case, please help!
>
> --
> Thanks
> Sebastien

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      11th Jul 2007
I think Vergel answered your question, but you could use:

with worksheets("sheet2")
.select
.range("a1:b9").select
end with

It'll save you some keystrokes and I think makes the code easier to read.

Sebastien wrote:
>
> Good day,
>
> Situation:
>
> I am having a macro in "sheet_1" that is doing a whole bunch of operations.
> The macro uses a combination of absolute references such as:
>
> Cells(1, "C") = ...
>
> as well as relative references such as:
>
> Range("B1").Select
> Selection.End(xlDown).Select
> ActiveCell.Offset(1, 1).Select
>
> My problem:
>
> When I need the macro to execute an operation in the next sheet of my
> workbook "sheet_2", I write something as simple as:
>
> Sheets("sheet_2").Select
> Range("A3:A200").Select
>
> but I have an error message at the second line "Range("A3:A200").Select". I
> have never seen this kind of error before. My second line must be written as
>
> Sheets("sheet_2").Range("A2:K2").Select
>
> Usually, When I select a sheet, I do not need to "re-select" it in each line
> of the macro, but for this one, I am obliged to do so and it gets quite
> annoying.
>
> I think there is a problem of reference (absolute vs relative). Or maybe my
> macro is dedicated to sheet_1 only? If this is the case, how do I make it
> valid for the whole workbook? In any case, please help!
>
> --
> Thanks
> Sebastien


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mixing absolute & relative reference Gilbert DE CEULAER Microsoft Excel Worksheet Functions 3 23rd Dec 2008 11:54 AM
Combining absolute and relative reference for sum =?Utf-8?B?RGVuaXNl?= Microsoft Excel Programming 1 4th Nov 2004 06:34 AM
Mass Relative to Absolute Reference Change kraljb Microsoft Excel Misc 4 17th Sep 2004 01:26 AM
Re: Something other than relative or absolute cell reference? Frank Kabel Microsoft Excel Misc 4 14th Jul 2004 08:36 PM
Re: Something other than relative or absolute cell reference? Don Guillett Microsoft Excel Misc 0 14th Jul 2004 07:47 PM


Features
 

Advertising
 

Newsgroups
 


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