ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   (Probably) simple question (https://www.excelbanter.com/excel-programming/292135-probably-simple-question.html)

Jonathan Vickers

(Probably) simple question
 
Hi,

I have a macro, but when it runs I want the cell that is selected
immediately afterwards to be the cell that was selected immediately before
the macro ran.

I am sure that this is quite an easy thing to do in VB, but I don't know how
to do it.

Any help is much appreciated,

Jon.



Frank Kabel

(Probably) simple question
 
Hi
try something like

sub foo()
Dim rng as range
set rng = Activecell
'...
'...your macro code
'...
rng.select
end sub

if you also change the worksheet and/or workbook you have to store them
in a similar way


--
Regards
Frank Kabel
Frankfurt, Germany

Jonathan Vickers wrote:
Hi,

I have a macro, but when it runs I want the cell that is selected
immediately afterwards to be the cell that was selected immediately
before the macro ran.

I am sure that this is quite an easy thing to do in VB, but I don't
know how to do it.

Any help is much appreciated,

Jon.



Dick Kusleika[_3_]

(Probably) simple question
 
Jon

In addition to Franks response, you can redesign your macro so that the
selection doesn't change when it runs. It is generally not necessary to
select objects in order to work with them. Whenever you have a construct
like this

Range("A1").Select
Selection.Interior.ColorIndex = 1

you can change it to simply

Range("A1").Interior.ColorIndex = 1

By not selecting objects in order to change their properties or invoke their
methods, you can greatly increase the speed at which your macro runs. It
also looks cooler.

If your code isn't too lengthy, you can post it here and I will show you how
to get around selecting.

--
Dick Kusleika
MVP - Excel
www.dicks-clicks.com
Post all replies to the newsgroup.

"Jonathan Vickers" wrote in message
...
Hi,

I have a macro, but when it runs I want the cell that is selected
immediately afterwards to be the cell that was selected immediately before
the macro ran.

I am sure that this is quite an easy thing to do in VB, but I don't know

how
to do it.

Any help is much appreciated,

Jon.






All times are GMT +1. The time now is 10:05 AM.

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