(Probably) simple question

  • Thread starter Thread starter Jonathan Vickers
  • Start date Start date
J

Jonathan Vickers

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.
 
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
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top