Apply a macro to a pre-selected range of cells

  • Thread starter Thread starter tim knowles
  • Start date Start date
T

tim knowles

I wish to create a macro and assign it to a button such
that it formats the range of cells that has been selected
immediately prior to clicking the button (in the same way
that the "," or "%" format buttons work. But each time I
record the macro, it refers to the cell that is
highlighted as Range.Select."A5" or Range.Select."C1:J14"
etc.

How can I just refer to which-ever range has been selected?

thanks
 
Did you try something like:

Sub x()

Dim Rg As Range

Set Rg = Selection

'your code here

Set Rg = Nothing

End Su
 
Tim,

Try something like

Selection.NumberFormat = "0%"

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 

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