Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
momma
 
Posts: n/a
Default 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?
  #2   Report Post  
Posted to microsoft.public.excel.misc
L. Howard Kittle
 
Posts: n/a
Default 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?



  #3   Report Post  
Posted to microsoft.public.excel.misc
flummi
 
Posts: n/a
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Button not bring up Macro I created A.S. Excel Discussion (Misc queries) 1 July 22nd 05 10:21 PM
Assign a macro to Command Button Object dallin Excel Discussion (Misc queries) 2 July 13th 05 03:50 AM
Macro Button Maggie Excel Discussion (Misc queries) 3 June 28th 05 04:29 AM
Attaching a macro to a VB button on a form WildGlio Excel Worksheet Functions 2 March 25th 05 11:11 PM
Assigning a macro to a "button" Yvon Excel Discussion (Misc queries) 6 February 8th 05 10:58 PM


All times are GMT +1. The time now is 08:56 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"