Reading Cell Address in VBA

  • Thread starter Thread starter Richard
  • Start date Start date
R

Richard

OS: MS Xp
Excel 2003

I am in say cell E127 and need t go to cell B2. I then need to return to
cell E127.
Problem is E127 is different each time. How do I read the cell address in
VBA so that I may return to it?
Thanks in advanced.
 
Declare a range object variable:
Dim StartCell as Range

When you need to remember the current active cell's address:
Set StartCell = ActiveCell

When you want to return to that cell later:
StartCell.Activate

At the end of your macro, add:
Set StartCell = Nothing

Hope this helps,

Hutch
 
something like this...

Dim rngFirstCell as Range, rngSecondCell as Range
Set rngFirstCell = ActiveCell 'Assuming E127 is the active cell here
Set rngSecondCell = Cells(2,2) 'i.e. B2

'---
'Code that does something to rngSecondCell
'---

rngFirstCell.Activate 'Go back to e127
 
Back
Top