Moving Cursor & Sheet back to the Original Location

R

Ricky Pang

Hello Experts,
Through a macro, I open a file to select various ranges in different
sheets to copy to another workbook. Is there a way to move the cursor
back to the cursor's original location plus go back to the original
sheet, that was before I activated the macro? This is so that other
users can continue with their work without having to search for their
last location.

Here's an excerpt of switching to another workbook to select a few
ranges, copy and paste:

wkbk.Application.Goto Reference:="ListA"
Selection.Copy
'Is there something that I could put here to move the
'cursor back to its original location?
curWks.Range("PasteListA").PasteSpecial _
Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

wkbk.Application.Goto Reference:="ListB"
Selection.Copy
'Is there something that I could put here that make the active sheet be
the original sheet again?
curWks.Range("PasteListB").PasteSpecial _
Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

Thanks in advance,
Ricky
 
D

DM Unseen

Ricky,

almost all XL operations you want can be accomplished *without*
selection or activation, so you do not need to *move* the cursor. The
problem is the macro recorder doesn't realise this, and looking at your
code, i guess you're probably still very dependent on the recorder.

So

wkbk.Application.Goto Reference:="ListA"
Selection.Copy

could well become

Range("LIstA").Copy

The following does what you requested:

DIm rngStart as Range
' start with
set rngStart = Application.ActiveCell

' do all your stuff

'end with
rngStart.Activate

I suspect you're still on the "macrorecorder" stage. I would suggest
reading up on VBA, this will improve your XL skills to no end;)

DM Unseen
 
R

Ricky Pang

Thank-you DM,
That's exactly what I'm looking for. Agreed, VBA is a great tool to
streamline the procedures. I've downloaded some ebooks to use as a
guide.

Ricky
 

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