Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default How do I: vba to create column sorting buttons/hyperlink

I would like to create a VBA that will take my column headings and create
either a hyperlink or a button for each column heading.
When the link/button is clicked it will sort the table by that column.

Thx,
Ronio
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default How do I: vba to create column sorting buttons/hyperlink

Inserting this into the ThisWorkbook section might get you close to what you
are looking for (although it does require double-clicking on the header
cells):

Dim rTable As Range

Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target
As Range, Cancel As Boolean)
Set rTable = TableRange()
If Target.Row = headerRow Then Call SortByColHeader(Target)
End Sub

Function TableRange() As Range
Dim topLeft As Range
Set topLeft = Range("A1")
topLeft.Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Set TableRange = Selection
End Function

Sub SortByColHeader(r As Range)
rTable.Select
Selection.Sort Key1:=r, Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
'rTable.Cells(1, 1).Select
End Sub

Hope this helped,
Rolf

"Ronio" wrote:

I would like to create a VBA that will take my column headings and create
either a hyperlink or a button for each column heading.
When the link/button is clicked it will sort the table by that column.

Thx,
Ronio

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default How do I: vba to create column sorting buttons/hyperlink

Thank-you Rolf,

this worked perfectly.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default How do I: vba to create column sorting buttons/hyperlink

using the sheet's on double click event makes this trivial:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
'sorts by the selected column, assumes row 1 is a header row
If Target.Row = 1 Then
Target.CurrentRegion.Sort Target, xlAscending, header:=xlYes
End If

End Sub

"Ronio" wrote in message
...
I would like to create a VBA that will take my column headings and create
either a hyperlink or a button for each column heading.
When the link/button is clicked it will sort the table by that column.

Thx,
Ronio


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
Hyperlink using buttons Melisa Hutchins Excel Discussion (Misc queries) 0 January 6th 11 07:15 PM
create option buttons Kev New Users to Excel 1 December 19th 06 09:12 AM
How to create buttons? play4you New Users to Excel 2 November 22nd 06 07:36 PM
How do I create a hyperlink to a cell with the hyperlink function S. Bevins Excel Worksheet Functions 2 July 20th 06 08:06 PM
Protect sorting buttons in menubar Tom Excel Programming 2 January 22nd 04 07:57 PM


All times are GMT +1. The time now is 11:58 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"