PC Review


Reply
Thread Tools Rate Thread

How do I make references to cells in subroutines relative?

 
 
=?Utf-8?B?QXRyZWlkZXM=?=
Guest
Posts: n/a
 
      16th Nov 2006
How do I make references to cells in subroutines relative?

For example, if part of my subroutine is:

Range("A533").Select

then I insert or delete cells in the spreadsheet, the references to these
cells in the macro stay the same, and are thus incorrect. They always have to
be updated manually. How can I make these change automatically when I modify
the spreadsheet?

Or is there a better way to reference cells in the worksheet?

Thanks
Atreides
 
Reply With Quote
 
 
 
 
Ardus Petus
Guest
Posts: n/a
 
      16th Nov 2006
Use named range instead of literal

Cheers
--
AP

"Atreides" <atreides1AThotmailD0Tcom> a écrit dans le message de news:
713AE028-8CC1-455C-872A-(E-Mail Removed)...
> How do I make references to cells in subroutines relative?
>
> For example, if part of my subroutine is:
>
> Range("A533").Select
>
> then I insert or delete cells in the spreadsheet, the references to these
> cells in the macro stay the same, and are thus incorrect. They always have
> to
> be updated manually. How can I make these change automatically when I
> modify
> the spreadsheet?
>
> Or is there a better way to reference cells in the worksheet?
>
> Thanks
> Atreides



 
Reply With Quote
 
=?Utf-8?B?QXRyZWlkZXM=?=
Guest
Posts: n/a
 
      16th Nov 2006
Hi Ardus,

Sorry, I'm not sure what you mean by that. I've leart VBA by experiment
rather than instruction, so I'm not really familiar with the terms. How do I
use a named range?

Thanks
Peter

"Ardus Petus" wrote:

> Use named range instead of literal
>
> Cheers
> --
> AP
>
> "Atreides" <atreides1AThotmailD0Tcom> a écrit dans le message de news:
> 713AE028-8CC1-455C-872A-(E-Mail Removed)...
> > How do I make references to cells in subroutines relative?
> >
> > For example, if part of my subroutine is:
> >
> > Range("A533").Select
> >
> > then I insert or delete cells in the spreadsheet, the references to these
> > cells in the macro stay the same, and are thus incorrect. They always have
> > to
> > be updated manually. How can I make these change automatically when I
> > modify
> > the spreadsheet?
> >
> > Or is there a better way to reference cells in the worksheet?
> >
> > Thanks
> > Atreides

>
>
>

 
Reply With Quote
 
Ardus Petus
Guest
Posts: n/a
 
      16th Nov 2006
Select the range you want to name
Use menu Insert>Name>Define
enter a valid name (eg: MyRange)
click OK

Now you can use:
Range("MyRange").Select
anywhere in your code.

Insertions and deletions will be reflected in your name definaition

Cheers,
--
AP


"Atreides" <atreides1AThotmailD0Tcom> a écrit dans le message de news:
C36E5F06-C5E7-4662-9CEA-(E-Mail Removed)...
> Hi Ardus,
>
> Sorry, I'm not sure what you mean by that. I've leart VBA by experiment
> rather than instruction, so I'm not really familiar with the terms. How do
> I
> use a named range?
>
> Thanks
> Peter
>
> "Ardus Petus" wrote:
>
>> Use named range instead of literal
>>
>> Cheers
>> --
>> AP
>>
>> "Atreides" <atreides1AThotmailD0Tcom> a écrit dans le message de news:
>> 713AE028-8CC1-455C-872A-(E-Mail Removed)...
>> > How do I make references to cells in subroutines relative?
>> >
>> > For example, if part of my subroutine is:
>> >
>> > Range("A533").Select
>> >
>> > then I insert or delete cells in the spreadsheet, the references to
>> > these
>> > cells in the macro stay the same, and are thus incorrect. They always
>> > have
>> > to
>> > be updated manually. How can I make these change automatically when I
>> > modify
>> > the spreadsheet?
>> >
>> > Or is there a better way to reference cells in the worksheet?
>> >
>> > Thanks
>> > Atreides

>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?QXRyZWlkZXM=?=
Guest
Posts: n/a
 
      21st Nov 2006
Thanks Ardus, that explains it well.

It seems that Names are even more useful than I previously thought!

Atreides

"Ardus Petus" wrote:

> Select the range you want to name
> Use menu Insert>Name>Define
> enter a valid name (eg: MyRange)
> click OK
>
> Now you can use:
> Range("MyRange").Select
> anywhere in your code.
>
> Insertions and deletions will be reflected in your name definaition
>
> Cheers,
> --
> AP
>
>
> "Atreides" <atreides1AThotmailD0Tcom> a écrit dans le message de news:
> C36E5F06-C5E7-4662-9CEA-(E-Mail Removed)...
> > Hi Ardus,
> >
> > Sorry, I'm not sure what you mean by that. I've leart VBA by experiment
> > rather than instruction, so I'm not really familiar with the terms. How do
> > I
> > use a named range?
> >
> > Thanks
> > Peter
> >
> > "Ardus Petus" wrote:
> >
> >> Use named range instead of literal
> >>
> >> Cheers
> >> --
> >> AP
> >>
> >> "Atreides" <atreides1AThotmailD0Tcom> a écrit dans le message de news:
> >> 713AE028-8CC1-455C-872A-(E-Mail Removed)...
> >> > How do I make references to cells in subroutines relative?
> >> >
> >> > For example, if part of my subroutine is:
> >> >
> >> > Range("A533").Select
> >> >
> >> > then I insert or delete cells in the spreadsheet, the references to
> >> > these
> >> > cells in the macro stay the same, and are thus incorrect. They always
> >> > have
> >> > to
> >> > be updated manually. How can I make these change automatically when I
> >> > modify
> >> > the spreadsheet?
> >> >
> >> > Or is there a better way to reference cells in the worksheet?
> >> >
> >> > Thanks
> >> > Atreides
> >>
> >>
> >>

>
>
>

 
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
Naming Cells Using Relative Cell References Inobugs Microsoft Excel Worksheet Functions 1 19th Apr 2009 03:50 PM
Help with converting a block of cells with Absolute and mixed references to relative references Vulcan Microsoft Excel Worksheet Functions 3 13th Dec 2007 11:43 PM
Module to make all absolute references relative =?Utf-8?B?UHJvX0QgTWlrZQ==?= Microsoft Excel Programming 3 26th May 2006 06:41 PM
How to make a macro with relative references Hall Microsoft Excel Discussion 4 17th Mar 2006 02:54 AM
Using named cells in relative references rbekka33 Microsoft Excel Programming 1 2nd Nov 2004 10:08 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:35 PM.