Macro - Return to starting cell

G

Guest

I am writing a macro that will always start in a different cell, but needs to
reference back to the starting cell each time it is run. For example, if the
cursor is in cell d3 when the macro is run, the macro must return to d3 when
finished. The next time the macro is run, it will start in e3, and return to
e3 when finished. I use the macro recorder to write my macros, how do I
write it to have the routine always end in the starting cell?
 
J

JE McGimpsey

One way:

Dim rReturn As Range
Set rReturn = ActiveCell

'do your routine here

rReturn.Activate
 
G

Guest

OK I'm lost: How is this written

1) The cursor is in d3.
2) goto a3, copy a3:a7
3) *** how do i automate the return to d3? ***
4) paste to d3:d7
 
J

JE McGimpsey

To do it the way you say:

Dim rReturn As Range
Set rReturn = ActiveCell
Range("A3:A7").Select
Selection.Copy
rReturn.Activate
ActiveSheet.Paste

OTOH, you could replace the whole thing with

Range("A3:A7").Copy Destination:=ActiveCell
 
G

Guest

JE - Thanks for quick responses. How do I record the macro? Using macro
recorder is pretty limiting. It is easier said than done. Thanks - Sony
 
R

R..VENKATARAMAN

try something like this
(at ther beginning of the macro after public sub -----())

dim cc as range
set cc=activecell
then other code staements

(at the end of the macro before end sub
type

cc.select

try this and see whether you get what you want.
 
B

Bob Phillips

You don't.

Go into the VBIDE, Alt-F11, Insert a new code module, Insert>Module, and
add the macro

Sub CopyData()
Range("A3:A7").Copy Destination:=ActiveCell
End Sub

and run that from excel.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)
 
G

Guest

JE - I got it. Thankyou very much for the insight on this one. I have some
final mods to make and good to go. Thanks again - Sony
 

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