Share via

Macro ending at cursor

Anonymous
2022-06-25T18:18:11+00:00

On my Excel/Office 2007 on Windows 10.

I have a macro that ends with ->  Range("A1").Select.

I’d like to heave it return to where my cursor is, instead of cell A1.

Is that possible ? And if so, how do I do that ?

Thanks,

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

OssieMac 48,001 Reputation points Volunteer Moderator
2022-06-26T06:02:04+00:00
I'm sorry, but I don't understand where this would go.

This is my recorded macro...

Cells.Select

Range("A112").Activate

Selection.Replace What:="?v=", Replacement:="/", LookAt:=xlPart, _

SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _

ReplaceFormat:=False

Range("A1").Select

End Sub

Thanks again,

I am not sure I am correctly understanding where you want to return to.

Do you want it to return to where the cursor was before running the macro because that is what I thought you meant and the comments after the lines of code indicate where the code goes in your macro.

Or maybe you want it to return to the first cell that had the value replaced or maybe the last cell that had the value replaced.

If you want it to return to the cell where it was before running the macro then the following line should be the first line to process in the macro

Set rngActiveCell = ActiveCell     'First line of code to run 

Then the following line should be the last line in the macro.

Application.Goto rngActiveCell    'Last line of code to run

Was this answer helpful?

3 people found this answer helpful.
0 comments No comments

8 additional answers

Sort by: Most helpful
  1. Anonymous
    2022-06-25T21:50:35+00:00

    On my Excel/Office 2007 on Windows 10.

    I have a macro that ends with ->  Range("A1").Select.

    I’d like to heave it return to where my cursor is, instead of cell A1.

    Is that possible ? And if so, how do I do that ?

    First thing to try is comment out the select line...

    ' Range("A1").Select

    (note the apostrophe)

    then see what happens when you run the code again.

    If that doesn't do what you want then you need to:

    1. select the correct sheet
    2. select the correct cell.

    In that order.

    '---
    Nothing Left to Lose

    https://1drv.ms/u/s!Au8Lyt79SOuhZw2MCH7_7MuLj04?e=sAwbHU

    (free excel programs)

    Thanks but this didn't work.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2022-06-25T21:49:15+00:00

    a=application.activecell

    ......

    'Range("A1").Select.

    a.select

    I'm sorry.

    I'm not sure what needs to go where.

    Specifically, what goes between ReplaceFormat:=False & End Sub

    ReplaceFormat:=False

    'Range("A1").Select 
    

    End Sub

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2022-06-25T21:01:34+00:00

    a=application.activecell

    ......

    'Range("A1").Select.

    a.select

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2022-06-25T18:52:10+00:00

    On my Excel/Office 2007 on Windows 10.

    I have a macro that ends with ->  Range("A1").Select.

    I’d like to heave it return to where my cursor is, instead of cell A1.

    Is that possible ? And if so, how do I do that ?

    First thing to try is comment out the select line...

    ' Range("A1").Select

    (note the apostrophe)

    then see what happens when you run the code again.

    If that doesn't do what you want then you need to:

    1. select the correct sheet
    2. select the correct cell.

    In that order.

    '---
    Nothing Left to Lose

    https://1drv.ms/u/s!Au8Lyt79SOuhZw2MCH7_7MuLj04?e=sAwbHU

    (free excel programs)

    Was this answer helpful?

    0 comments No comments