Syntax to save ActiveCell to MyActiveCell then select later

D

Dennis

Using 2003

Have been attempting to capture the range (or whatever I need) of an active cell to reselect later.

I would like to perform the essence of the code below (but the syntax is not correct)

Sub ReturnToOriginalActiveCell()

Dim MyActiveCell As Range
MyActiveCell = ActiveCell.??????????

[Other VBA Code]


MyActiveCell.Select

End Sub

TIA Dennis
 
F

Frank Kabel

Hi
try
sub foo()
dim old_cell as range
set old_cell = activecell
'your code
old_cell.select
end sub
 
R

Ron de Bruin

Hi Dennis

Use Set

Sub ReturnToOriginalActiveCell()
Dim MyActiveCell As Range
Set MyActiveCell = ActiveCell

' [Other VBA Code]
MyActiveCell.Select
End Sub
 
D

Dave Peterson

And in case you change worksheets/workbooks:

Sub ReturnToOriginalActiveCell()

Dim MyActiveCell As Range
'you need to use SET here.
set MyActiveCell = ActiveCell

[Other VBA Code]


Application.goto MyActiveCell ',scroll:=true

End Sub

Try it once with scroll:=true and without scroll:=true to see the difference.
Using 2003

Have been attempting to capture the range (or whatever I need) of an active cell to reselect later.

I would like to perform the essence of the code below (but the syntax is not correct)

Sub ReturnToOriginalActiveCell()

Dim MyActiveCell As Range
MyActiveCell = ActiveCell.??????????

[Other VBA Code]

MyActiveCell.Select

End Sub

TIA Dennis
 

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