I'm still not sure what I'm supposed to do. I tried the code you provided in
VB, but when I inserted a row the code: set r = range("D10") did not
update to: set r = range("D11").
Forgetting about auto-updating the macro, is there any way to select a cell
by the variable name instead of the cell location?
I tried Range("var_name").Select but that does not work.
Thanks,
Adam
> hi
> you might try variables
[quoted text clipped - 31 lines]
> >
> > Adam
Dave Peterson - 20 May 2008 19:32 GMT
In order to select a range, the worksheet that holds that range must be selected
(or active). In order for the worksheet to be selected, the workbook that holds
that worksheet has to be selected.
So you could use:
Range("pop1d").parent.parent.activate 'workbook
Range("pop1d").parent.select 'worksheet
Range("pop1d").Select 'range
or
application.goto Range("pop1d"), scroll:=true 'or false
This does assume that you really have a range named "pop1d".
=====
There is nothing that I've seen that will adjust your code when you move cells
-- or insert/delete rows/columns.
That's the best thing about naming your ranges. The code shouldn't have to
change.
> I'm still not sure what I'm supposed to do. I tried the code you provided in
> VB, but when I inserted a row the code: set r = range("D10") did not
[quoted text clipped - 44 lines]
> > >
> > > Adam

Signature
Dave Peterson
Dave Peterson - 20 May 2008 19:54 GMT
In order to select a range, the worksheet that holds that range must be selected
(or active). In order for the worksheet to be selected, the workbook that holds
that worksheet has to be ACTIVATED (typo fixed here).
> In order to select a range, the worksheet that holds that range must be selected
> (or active). In order for the worksheet to be selected, the workbook that holds
[quoted text clipped - 71 lines]
>
> Dave Peterson

Signature
Dave Peterson
FSt1 - 20 May 2008 19:38 GMT
hi,
yes you are right, the code did not update. but on the sheet the variable
which was set prior to add row shifted to d11 after the row was added. to
test do this
dim r as range
set r = range("D10")
r.select
rows("6:6").insert shift:=xldown
r.select
msgbox r.address
you will set that though set at D10 prior to add row, it is now selecting
D11 and the variable is now D11 after add row.
Regards
FSt1
> I'm still not sure what I'm supposed to do. I tried the code you provided in
> VB, but when I inserted a row the code: set r = range("D10") did not
[quoted text clipped - 44 lines]
> > >
> > > Adam
Gord Dibben - 20 May 2008 19:52 GMT
What doesn't work with that line?
Do you have a range named "var_name" ?
How did you name it?
Works for me in Excel 2003
Try these for testing only.
Sub test()
Range("A10").Select
Selection.Name = "var_name"
Range("A9").Select
Selection.Resize(4).EntireRow.Insert
End Sub
Sub test2()
Range("var_name").Select
msgbox selection.address
End Sub
Gord Dibben MS Excel MVP
>I tried Range("var_name").Select but that does not work.