PDA

View Full Version : Solved: Sorting by Code



GDillon
02-19-2006, 07:23 PM
I have a sheet that I need to sort perferrably by VBA Code. The data starts at B3-H3 and this is one record and continues down the page until it gets to B6854-H6854. I sort this to Column B Ascending. Can this be set up on a command button that I can put on the page? Please provide code and installation instructions. Thanks in advance

XLGibbs
02-19-2006, 07:31 PM
If you attach a spreadsheeet, I can set it up for you with instructions in the code.

However, the code is



Sub sortsheet()
Dim rngSort as Range

Set rngSort = ActiveSheet.Range("B3:H6854")

rngSort.Sort Key1:=Range("B3"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

set rngSort = Nothing

End Sub


To assign this a button, go to toolbars > view >Forms

On the forms toolbar you can mouse over the tools, but the one you want "looks" like a button. click the button and draw one on the sheet. Right click to assign Macro, and choose the macro above.

To install the code. Right-click the sheet and select view code. Copy the code there.

Hope that helps, and Welcome to VBAX!http://vbaexpress.com/forum/images/smilies/023.gif

XLGibbs
02-19-2006, 07:40 PM
http://www.mrexcel.com/board2/viewtopic.php?t=196074

Cross Post. Please see the important information in my signature link.

GDillon
02-19-2006, 08:27 PM
Thanks for your reply, I have attached a actual screen shot of my page


EDIT: Screenshot JavaScript code removed, did not work.

The screenshot post does not work quite like that...you can save the screenshot, and insert the picture, but it is not necessary. You can just attach an excel file as well by going Advanced>Manage attachments.

Thanks

XLGibbs/Pete

XLGibbs
02-19-2006, 08:47 PM
GDillon,

I had to remove the result of your screenshot. It appeared as a massive amount of javascript, not an image, so you can attach your spreadsheet if you like using advanced > manage attachments.

Sanitize sensitive data of course...

GDillon
02-19-2006, 09:00 PM
Ok, Sorry :banghead: I hope I got it right this time, This is a copy of the page and the cells are b3:h6854

XLGibbs
02-19-2006, 09:06 PM
Button with sort code attached.

GDillon
02-19-2006, 09:22 PM
This is exactly what I needed, Thanks for your Help, SOLVED!!

XLGibbs
02-19-2006, 09:25 PM
Happy to help out.