ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   How do I use a macro button (https://www.excelbanter.com/excel-discussion-misc-queries/69580-how-do-i-use-macro-button.html)

momma

How do I use a macro button
 
I would like to add a macro button that will automatically re-sort a string
of numbers that are calculated at random. Column A are the numbers to which
I want to sort while Column B is @rand. Does anyone know how I can
accomplish this?

L. Howard Kittle

How do I use a macro button
 
Try this macro assigned to a button from the Forms menu bar.

Sub SortIt()
Dim Lrow As Long
Dim Drng As Range
Lrow = Cells(Rows.Count, "A").End(xlUp).Row
Set Drng = Range("A1:B" & Lrow)
Drng.Sort Key1:=Range("B1"), Order1:=xlAscending
End Sub

HTH
Regards,
Howard

"momma" wrote in message
...
I would like to add a macro button that will automatically re-sort a string
of numbers that are calculated at random. Column A are the numbers to
which
I want to sort while Column B is @rand. Does anyone know how I can
accomplish this?




flummi

How do I use a macro button
 
Or:

select tools--macro--record a macro,
when asked for the macro name type: sort
under "Store in" select "This workbook"
click ok
select the range to sort,
select data--sort and perform the sort,
select tools--macro--stop recording
select view--toolbars--control toolbox
click the design button (green triangle)
click the command button icon
click somewhere on your sheet, hold and drag to the right and down to
create a button
right click in the new button and from the context menu select 'view
code'
between the lines "private sub" and "end sub" type the name of your
macro which was 'sort'
close the VBA window
on your sheet click the design button
click the new button to test it.

Mind that the sort range is "fixed" in the macro! So if you need to
expand the sort range be sure to reflect the change in the macro.

Hans



All times are GMT +1. The time now is 04:16 AM.

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