close

In my worksheet I am going to launch a macro from a different cell address
each time it is run. I want the macro execution to always complete in the
starting cell
(return to it). Any ideas please?

SonySony, you can do most things in VBA without selecting the cells, may want to
post your code and see if that is the case, that said, give this a try

Set Oldsheet = ActiveSheet
oldcell = Selection.Address

'put your code here

Oldsheet.Select
Range(oldcell).Select--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 amp; 2003

quot;sony654quot; gt; wrote in message
...
gt; In my worksheet I am going to launch a macro from a different cell address
gt; each time it is run. I want the macro execution to always complete in the
gt; starting cell
gt; (return to it). Any ideas please?
gt;
gt; Sony
gt;
Paul - Here is how it is supposed to work: How do I fit your code in to mine
below (this is my current code (below)) Thanks for reviewing

A B C D E F G H
1
2 10 10 11
3 12 12 8
4 8 8 7
5 9 9 7
6
7 39 39 33
8
9

Cell e2 will be active before the macro is run the first time. The macro
will (f5) go to and select range b2:b7, and copy back to d2:d7. The second
time run, cell e2 will be active, and should copy b2:b7 back to e2:e7. I
always want the b2:b7 selection to be copied back to the starting cell.

Sub Macro4()
'
' Macro4 Macro
' Macro recorded 2/4/2006 by slpic
'
' Keyboard Shortcut: Ctrl w
'
Range(quot;F6quot;).Select
Application.Goto Reference:=quot;R2C2quot;
Range(quot;b2:b7quot;).Select
Selection.Copy
Range(quot;d2quot;).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range(quot;F7quot;).Select
End Sub--
Sony Luvyquot;Paul Bquot; wrote:

gt; Sony, you can do most things in VBA without selecting the cells, may want to
gt; post your code and see if that is the case, that said, give this a try
gt;
gt; Set Oldsheet = ActiveSheet
gt; oldcell = Selection.Address
gt;
gt; 'put your code here
gt;
gt; Oldsheet.Select
gt; Range(oldcell).Select
gt;
gt;
gt; --
gt; Paul B
gt; Always backup your data before trying something new
gt; Please post any response to the newsgroups so others can benefit from it
gt; Feedback on answers is always appreciated!
gt; Using Excel 2002 amp; 2003
gt;
gt; quot;sony654quot; gt; wrote in message
gt; ...
gt; gt; In my worksheet I am going to launch a macro from a different cell address
gt; gt; each time it is run. I want the macro execution to always complete in the
gt; gt; starting cell
gt; gt; (return to it). Any ideas please?
gt; gt;
gt; gt; Sony
gt; gt;
gt;
gt;
gt;

Sub Macro_X()
Dim r As String
r = ActiveCell.Address
MsgBox r
Range(quot;A1quot;).Select
MsgBox quot;Cell A1 has been selectedquot;
Range(r).Activate
End SubOn Sat, 4 Feb 2006 18:11:26 -0800, quot;sony654quot;
gt; wrote:

gt;In my worksheet I am going to launch a macro from a different cell address
gt;each time it is run. I want the macro execution to always complete in the
gt;starting cell
gt;(return to it). Any ideas please?
gt;
gt; Sony

sony654, I am not clear on what you want to do, at first thought you only
wanted to go back to the cell you were in when you started the macro, now quot;I
always want the b2:b7 selection to be copied back to the starting cellquot; in
your example e2 is the starting cell each time but you are putting the data
in d and then e?? maybe something like this will put what's in B2:B7 where
the activecell is at, will that work? Range(quot;B2:B7quot;).Copy
Destination:=ActiveCell
--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 amp; 2003

quot;sony654quot; gt; wrote in message
...
gt; Paul - Here is how it is supposed to work: How do I fit your code in to
mine
gt; below (this is my current code (below)) Thanks for reviewing
gt;
gt; A B C D E F G H
gt; 1
gt; 2 10 10 11
gt; 3 12 12 8
gt; 4 8 8 7
gt; 5 9 9 7
gt; 6
gt; 7 39 39 33
gt; 8
gt; 9
gt;
gt; Cell e2 will be active before the macro is run the first time. The macro
gt; will (f5) go to and select range b2:b7, and copy back to d2:d7. The
second
gt; time run, cell e2 will be active, and should copy b2:b7 back to e2:e7. I
gt; always want the b2:b7 selection to be copied back to the starting cell.
gt;
gt; Sub Macro4()
gt; '
gt; ' Macro4 Macro
gt; ' Macro recorded 2/4/2006 by slpic
gt; '
gt; ' Keyboard Shortcut: Ctrl w
gt; '
gt; Range(quot;F6quot;).Select
gt; Application.Goto Reference:=quot;R2C2quot;
gt; Range(quot;b2:b7quot;).Select
gt; Selection.Copy
gt; Range(quot;d2quot;).Select
gt; ActiveSheet.Paste
gt; Application.CutCopyMode = False
gt; Range(quot;F7quot;).Select
gt; End Sub
gt;
gt;
gt; --
gt; Sony Luvy
gt;
gt;
gt; quot;Paul Bquot; wrote:
gt;
gt; gt; Sony, you can do most things in VBA without selecting the cells, may
want to
gt; gt; post your code and see if that is the case, that said, give this a try
gt; gt;
gt; gt; Set Oldsheet = ActiveSheet
gt; gt; oldcell = Selection.Address
gt; gt;
gt; gt; 'put your code here
gt; gt;
gt; gt; Oldsheet.Select
gt; gt; Range(oldcell).Select
gt; gt;
gt; gt;
gt; gt; --
gt; gt; Paul B
gt; gt; Always backup your data before trying something new
gt; gt; Please post any response to the newsgroups so others can benefit from it
gt; gt; Feedback on answers is always appreciated!
gt; gt; Using Excel 2002 amp; 2003
gt; gt;
gt; gt; quot;sony654quot; gt; wrote in message
gt; gt; ...
gt; gt; gt; In my worksheet I am going to launch a macro from a different cell
address
gt; gt; gt; each time it is run. I want the macro execution to always complete in
the
gt; gt; gt; starting cell
gt; gt; gt; (return to it). Any ideas please?
gt; gt; gt;
gt; gt; gt; Sony
gt; gt; gt;
gt; gt;
gt; gt;
gt; gt;
Paul, Sorry. D2 is the active cell the first time the macro is run. Then E2
the second time the macro is run. The F2 the third time the macro is run,
and so on. B2:B5 is always copied back to the active cell position.
Hopefully that clarifies what I'm trying to accomplish. Thanks Sony
--
Sony Luvyquot;Paul Bquot; wrote:

gt; sony654, I am not clear on what you want to do, at first thought you only
gt; wanted to go back to the cell you were in when you started the macro, now quot;I
gt; always want the b2:b7 selection to be copied back to the starting cellquot; in
gt; your example e2 is the starting cell each time but you are putting the data
gt; in d and then e?? maybe something like this will put what's in B2:B7 where
gt; the activecell is at, will that work? Range(quot;B2:B7quot;).Copy
gt; Destination:=ActiveCell
gt;
gt;
gt;
gt; --
gt; Paul B
gt; Always backup your data before trying something new
gt; Please post any response to the newsgroups so others can benefit from it
gt; Feedback on answers is always appreciated!
gt; Using Excel 2002 amp; 2003
gt;
gt; quot;sony654quot; gt; wrote in message
gt; ...
gt; gt; Paul - Here is how it is supposed to work: How do I fit your code in to
gt; mine
gt; gt; below (this is my current code (below)) Thanks for reviewing
gt; gt;
gt; gt; A B C D E F G H
gt; gt; 1
gt; gt; 2 10 10 11
gt; gt; 3 12 12 8
gt; gt; 4 8 8 7
gt; gt; 5 9 9 7
gt; gt; 6
gt; gt; 7 39 39 33
gt; gt; 8
gt; gt; 9
gt; gt;
gt; gt; Cell e2 will be active before the macro is run the first time. The macro
gt; gt; will (f5) go to and select range b2:b7, and copy back to d2:d7. The
gt; second
gt; gt; time run, cell e2 will be active, and should copy b2:b7 back to e2:e7. I
gt; gt; always want the b2:b7 selection to be copied back to the starting cell.
gt; gt;
gt; gt; Sub Macro4()
gt; gt; '
gt; gt; ' Macro4 Macro
gt; gt; ' Macro recorded 2/4/2006 by slpic
gt; gt; '
gt; gt; ' Keyboard Shortcut: Ctrl w
gt; gt; '
gt; gt; Range(quot;F6quot;).Select
gt; gt; Application.Goto Reference:=quot;R2C2quot;
gt; gt; Range(quot;b2:b7quot;).Select
gt; gt; Selection.Copy
gt; gt; Range(quot;d2quot;).Select
gt; gt; ActiveSheet.Paste
gt; gt; Application.CutCopyMode = False
gt; gt; Range(quot;F7quot;).Select
gt; gt; End Sub
gt; gt;
gt; gt;
gt; gt; --
gt; gt; Sony Luvy
gt; gt;
gt; gt;
gt; gt; quot;Paul Bquot; wrote:
gt; gt;
gt; gt; gt; Sony, you can do most things in VBA without selecting the cells, may
gt; want to
gt; gt; gt; post your code and see if that is the case, that said, give this a try
gt; gt; gt;
gt; gt; gt; Set Oldsheet = ActiveSheet
gt; gt; gt; oldcell = Selection.Address
gt; gt; gt;
gt; gt; gt; 'put your code here
gt; gt; gt;
gt; gt; gt; Oldsheet.Select
gt; gt; gt; Range(oldcell).Select
gt; gt; gt;
gt; gt; gt;
gt; gt; gt; --
gt; gt; gt; Paul B
gt; gt; gt; Always backup your data before trying something new
gt; gt; gt; Please post any response to the newsgroups so others can benefit from it
gt; gt; gt; Feedback on answers is always appreciated!
gt; gt; gt; Using Excel 2002 amp; 2003
gt; gt; gt;
gt; gt; gt; quot;sony654quot; gt; wrote in message
gt; gt; gt; ...
gt; gt; gt; gt; In my worksheet I am going to launch a macro from a different cell
gt; address
gt; gt; gt; gt; each time it is run. I want the macro execution to always complete in
gt; the
gt; gt; gt; gt; starting cell
gt; gt; gt; gt; (return to it). Any ideas please?
gt; gt; gt; gt;
gt; gt; gt; gt; Sony
gt; gt; gt; gt;
gt; gt; gt;
gt; gt; gt;
gt; gt; gt;
gt;
gt;
gt;

Fred, Is ActiveCell.Address literal, or a quot;cellquot; address. I don;t mean to
look so elementary on this. But I appreciate your solution, it will be great
- Sony
--
Sony Luvyquot;Fred Holmesquot; wrote:

gt; Sub Macro_X()
gt; Dim r As String
gt; r = ActiveCell.Address
gt; MsgBox r
gt; Range(quot;A1quot;).Select
gt; MsgBox quot;Cell A1 has been selectedquot;
gt; Range(r).Activate
gt; End Sub
gt;
gt;
gt; On Sat, 4 Feb 2006 18:11:26 -0800, quot;sony654quot;
gt; gt; wrote:
gt;
gt; gt;In my worksheet I am going to launch a macro from a different cell address
gt; gt;each time it is run. I want the macro execution to always complete in the
gt; gt;starting cell
gt; gt;(return to it). Any ideas please?
gt; gt;
gt; gt; Sony
gt;

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 software 的頭像
    software

    software

    software 發表在 痞客邦 留言(0) 人氣()