ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   returning macro value to starting cell (different each time) (https://www.excelbanter.com/excel-worksheet-functions/69665-returning-macro-value-starting-cell-different-each-time.html)

sony654

returning macro value to starting cell (different each time)
 
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?

Sony


Paul B

returning macro value to starting cell (different each time)
 
Sony, 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 & 2003

"sony654" wrote in message
...
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?

Sony




sony654

returning macro value to starting cell (different each time)
 
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("F6").Select
Application.Goto Reference:="R2C2"
Range("b2:b7").Select
Selection.Copy
Range("d2").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("F7").Select
End Sub


--
Sony Luvy


"Paul B" wrote:

Sony, 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 & 2003

"sony654" wrote in message
...
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?

Sony





Fred Holmes

returning macro value to starting cell (different each time)
 
Sub Macro_X()
Dim r As String
r = ActiveCell.Address
MsgBox r
Range("A1").Select
MsgBox "Cell A1 has been selected"
Range(r).Activate
End Sub


On Sat, 4 Feb 2006 18:11:26 -0800, "sony654"
wrote:

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?

Sony


Paul B

returning macro value to starting cell (different each time)
 
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 "I
always want the b2:b7 selection to be copied back to the starting cell" 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("B2:B7").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 & 2003

"sony654" wrote in message
...
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("F6").Select
Application.Goto Reference:="R2C2"
Range("b2:b7").Select
Selection.Copy
Range("d2").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("F7").Select
End Sub


--
Sony Luvy


"Paul B" wrote:

Sony, 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 & 2003

"sony654" wrote in message
...
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?

Sony







sony654

returning macro value to starting cell (different each time)
 
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 Luvy


"Paul B" wrote:

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 "I
always want the b2:b7 selection to be copied back to the starting cell" 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("B2:B7").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 & 2003

"sony654" wrote in message
...
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("F6").Select
Application.Goto Reference:="R2C2"
Range("b2:b7").Select
Selection.Copy
Range("d2").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("F7").Select
End Sub


--
Sony Luvy


"Paul B" wrote:

Sony, 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 & 2003

"sony654" wrote in message
...
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?

Sony








sony654

returning macro value to starting cell (different each time)
 
Fred, Is ActiveCell.Address literal, or a "cell" address. I don;t mean to
look so elementary on this. But I appreciate your solution, it will be great
- Sony
--
Sony Luvy


"Fred Holmes" wrote:

Sub Macro_X()
Dim r As String
r = ActiveCell.Address
MsgBox r
Range("A1").Select
MsgBox "Cell A1 has been selected"
Range(r).Activate
End Sub


On Sat, 4 Feb 2006 18:11:26 -0800, "sony654"
wrote:

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?

Sony




All times are GMT +1. The time now is 01:55 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com