Consulting

Results 1 to 7 of 7

Thread: Solved: Go back to the cell where you started a macro

  1. #1
    VBAX Contributor
    Joined
    Feb 2008
    Posts
    193
    Location

    Solved: Go back to the cell where you started a macro

    Hello,

    can someone tell me the code to go back to the cell where you started a macro?
    The macro start button is floating (appears at the place you select a cell). The macro refreshes the values in the sheet and the cursor is now going back to cell A1. I would like the cursor to go back to the last cell you selected.

    Thx


    Ger

  2. #2
    VBAX Expert shrivallabha's Avatar
    Joined
    Jan 2010
    Location
    Mumbai
    Posts
    750
    Location
    Try something like this:
    [VBA]Public Sub Test()
    Dim rStart As Range 'Where Declaration is!
    Set srStart = ActiveCell 'At the beginning of code
    'Your Code here
    rStart.Select 'At the end of code
    End Sub[/VBA]
    Regards,
    --------------------------------------------------------------------------------------------------------
    Shrivallabha
    --------------------------------------------------------------------------------------------------------
    Using Excel 2016 in Home / 2010 in Office
    --------------------------------------------------------------------------------------------------------

  3. #3
    VBAX Contributor
    Joined
    Feb 2008
    Posts
    193
    Location
    I will try this tomorrow.

    Thx

    Ger

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Another way is to never leave that cell, that is, never select any other cell but just to act upon those cells indirectly.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Contributor
    Joined
    Feb 2008
    Posts
    193
    Location
    I just tried it. It works fine (after deleting the s in Set srStart)

    Thx

    Ger

  6. #6
    VBAX Contributor
    Joined
    Feb 2008
    Posts
    193
    Location
    Xld,
    because i have to delete rows, copy rows, resize etc the cursor is out of position. The solution from Shrivallabha works fine.
    The vba codes in this workbook is enormous. I think an expert can make i work faster an better, but i'm a novice.

    Ger

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Ger,

    It is rarely necessary to actually move the activecell, most things can be done upon an object (worksheet, range, etc.) without selecting those objects.

    But, as you say, getting the job done is the important thing, and if you have a solution and the preformance is acceptable, you're good.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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