+ Reply to Thread
Results 1 to 7 of 7

returning macro value to starting cell (different each time)

  1. #1
    sony654
    Guest

    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


  2. #2
    Paul B
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    > 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
    >




  3. #3
    sony654
    Guest

    Re: 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" <[email protected]> wrote in message
    > news:[email protected]...
    > > 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
    > >

    >
    >
    >


  4. #4
    Fred Holmes
    Guest

    Re: 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"
    <[email protected]> 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


  5. #5
    Paul B
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    > 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" <[email protected]> wrote in message
    > > news:[email protected]...
    > > > 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
    > > >

    > >
    > >
    > >




  6. #6
    sony654
    Guest

    Re: 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" <[email protected]> wrote in message
    > news:[email protected]...
    > > 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" <[email protected]> wrote in message
    > > > news:[email protected]...
    > > > > 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
    > > > >
    > > >
    > > >
    > > >

    >
    >
    >


  7. #7
    sony654
    Guest

    Re: 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"
    > <[email protected]> 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

    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1