Retain, restore selection?

M

Mekratrig

I created an Excel VBA macro that processes a list of items in a column
As a visual aid, I modified the code to select the row of the ite
being processed.

But now when the macro is finished executing, the row following th
last column entry remains selected/hilighted.

How can I:
1) Save whatever cell(s) are selected upon entry to macro execution;
2) Restore the original selection when code is ready to exit?

Many thanks in advance...


Mekratri
 
F

Frank Kabel

Hi
try
sub foo()
dim rng as range
set rng = selection
'your code
rng.select
end sub
 
J

JE McGimpsey

And if you want to restore the active cell in a multicell selection:

Public Sub foo()
Dim rSelect As Range
Dim rActive As Range

Set rSelect = Selection
Set rActive = ActiveCell

'do your thing

rSelect.Select
rActive.Activate
End Sub
 
F

Frank Kabel

Hi JE
good point :)
Frank
-----Original Message-----
And if you want to restore the active cell in a multicell selection:

Public Sub foo()
Dim rSelect As Range
Dim rActive As Range

Set rSelect = Selection
Set rActive = ActiveCell

'do your thing

rSelect.Select
rActive.Activate
End Sub



.
 

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