PDA

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



Ger
12-07-2011, 09:31 AM
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

shrivallabha
12-07-2011, 10:10 AM
Try something like this:
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

Ger
12-07-2011, 10:36 AM
I will try this tomorrow.

Thx

Ger

Bob Phillips
12-08-2011, 02:00 AM
Another way is to never leave that cell, that is, never select any other cell but just to act upon those cells indirectly.

Ger
12-08-2011, 02:02 AM
I just tried it. It works fine (after deleting the s in Set srStart)

Thx

Ger

Ger
12-08-2011, 02:20 AM
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

Bob Phillips
12-08-2011, 04:02 AM
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.