ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Reading Cell Address in VBA (https://www.excelbanter.com/excel-discussion-misc-queries/183783-reading-cell-address-vba.html)

Richard

Reading Cell Address in VBA
 
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.
--
Richard

Tom Hutchins

Reading Cell Address in VBA
 
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

"Richard" wrote:

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.
--
Richard


[email protected]

Reading Cell Address in VBA
 

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

On Apr 15, 1:16 pm, Richard wrote:
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.
--
Richard




All times are GMT +1. The time now is 08:20 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com