Macros with relative cell references

P

Pete

Sometimes the complex macros I write would be a lot more
useful if I could make them run in "context" based on
whatever cell I launch them from. Instead the way they
work with absolute cell references, they always go back
to whatever cell I started them on.

I tried a work-around that did not work--to base the
macro's start on a named range for the starting cell, and
use F5 (goto) in the macro's start with that named cell's
range value as the goto point, then after creating the
macro, going into Insert>>Name>>Define, and redefining
the named cell to another cell, but the macro still
starts at the original location.

Examples--I want to insert a row three rows down from the
block of rows I am working on, copy the values from the
first row of this block to this new row, and insert 1+
the value in column C from the row above to Col C of the
row I just inserted...or I want a macro that only deletes
the next 10 odd-numbered rows--you get the idea--very
context-specific macros. The HELP stuff on R1C1 does not
seem to work when I try it--I wrote a test macro where I
go to R[2]C[2] after turning R1C1 reference ON, and
repeatedly deleted rows, then tried it in different parts
of a spreadsheet, and it is still going to the same
absolute location and doing the same things over and over.

I'm hoping I don't need to learn Visual Basic to do this--
the Excel 2003 Help menu says R1C1 is supported.

Thanks in advance!

Pete
 
F

Frank Kabel

Hi
have a look at the offset property in the VBA help. e.g.
msgbox activecell.offset(1,1).value
 
P

Pete

Sehr gut--I will give it a try...thanks!
-----Original Message-----
Hi
have a look at the offset property in the VBA help. e.g.
msgbox activecell.offset(1,1).value

--
Regards
Frank Kabel
Frankfurt, Germany

Sometimes the complex macros I write would be a lot more
useful if I could make them run in "context" based on
whatever cell I launch them from. Instead the way they
work with absolute cell references, they always go back
to whatever cell I started them on.

I tried a work-around that did not work--to base the
macro's start on a named range for the starting cell, and
use F5 (goto) in the macro's start with that named cell's
range value as the goto point, then after creating the
macro, going into Insert>>Name>>Define, and redefining
the named cell to another cell, but the macro still
starts at the original location.

Examples--I want to insert a row three rows down from the
block of rows I am working on, copy the values from the
first row of this block to this new row, and insert 1+
the value in column C from the row above to Col C of the
row I just inserted...or I want a macro that only deletes
the next 10 odd-numbered rows--you get the idea--very
context-specific macros. The HELP stuff on R1C1 does not
seem to work when I try it--I wrote a test macro where I
go to R[2]C[2] after turning R1C1 reference ON, and
repeatedly deleted rows, then tried it in different parts
of a spreadsheet, and it is still going to the same
absolute location and doing the same things over and over.

I'm hoping I don't need to learn Visual Basic to do this--
the Excel 2003 Help menu says R1C1 is supported.

Thanks in advance!

Pete
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top