Save Cell address to activate it later in the procedure

L

loco

I am writing a procedure where i am standing in a cell.
Thereafter i shall automatically in the prosedure change the width of column
D-E from 20 to 40.

Afterwards i want the same cell to be active as it was before i started the
procedure.

I am using relative reference in the procedure.

Can someone please help me with how i save an cell adrress for reuse later?
 
D

Don Guillett

You do NOT have to goto columns d:e to set the column width
Sub widencolumn()
Columns("d:e").ColumnWidth = 40
End Sub

But, to answer your question
Sub goback()
returncell = ActiveCell.Address
Range("a33").Select
MsgBox ActiveCell.Address
Range(returncell).Select
End Sub
 
B

BobT

So, if I understand you code, you want to call a sub routine that takes care
of the column width piece then when it pops back to where you called the
procedure, you would like it to go back to the cell you started on. If
that's the case, simply do one one of the following:

(A) Create a string variable in the calling procedure and pass it the
address of the activecell.

(B) Create a Range variable and in the calling procedure pass it the
activecell.

Following your procedure call use the RANGE command to select your
variable's range.
 
L

loco

Thank you very much.
I could copy your code suggestion directly into my VB-code and it did run OK
at once.

Loco

Don Guillett skrev:
 

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