ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Apply a macro to a pre-selected range of cells (https://www.excelbanter.com/excel-programming/287715-apply-macro-pre-selected-range-cells.html)

tim knowles

Apply a macro to a pre-selected range of cells
 
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

Etien[_3_]

Apply a macro to a pre-selected range of cells
 
Did you try something like:

Sub x()

Dim Rg As Range

Set Rg = Selection

'your code here

Set Rg = Nothing

End Su

--
Message posted from http://www.ExcelForum.com


Bob Phillips[_6_]

Apply a macro to a pre-selected range of cells
 
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)

"tim knowles" wrote in message
...
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





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

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