Results 1 to 10 of 10

Thread: Sort Data When a Header Is Clicked

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Member littleiitin's Avatar
    Join Date
    Aug 2011
    Posts
    90
    Rep Power
    15
    Try this:
    Code:
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
         Dim HeaderRow As Long
         HeaderRow = Target.Row
         Select Case Target.Row
            Case HeaderRow
                If IsEmpty(Target.Value) Then Exit Sub
                Static MySortType As Integer
                If MySortType = 0 Then
                    MySortType = xlAscending
                ElseIf MySortType = xlAscending Then
                    MySortType = xlDescending
                ElseIf MySortType = xlDescending Then
                    MySortType = xlAscending
                End If
                'Target.CurrentRegion.Offset(1).Sort key1:=Target, order1:=MySortType, Header:=xlYes
                Target.CurrentRegion.Offset(0).Sort key1:=Target, order1:=MySortType, Header:=xlYes
        End Select
    
    End Sub



    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    Last edited by DocAElstein; 06-11-2023 at 01:22 PM.

  2. #2
    Senior Member
    Join Date
    Apr 2011
    Posts
    190
    Rep Power
    15
    Littleiitin
    It behave similar - you have to leave the cell and then put focus on it again. so lets say my header row is row 4 - If I click cell B4 - the data is sorted ascending from row 5 and down - now - to sort descending - I have to click some other cell then click B4 again - I am tryinmg to avoid having to click the other cell.
    xl2007 - Windows 7
    xl hates the 255 number

Similar Threads

  1. Sort Data Using Formula To Find Top X
    By mahmoud-lee in forum Excel Help
    Replies: 12
    Last Post: 06-02-2013, 10:13 PM
  2. Replies: 6
    Last Post: 05-10-2013, 01:13 AM
  3. Sort data sheet by right_click of mouse
    By Rasm in forum Excel and VBA Tips and Tricks
    Replies: 3
    Last Post: 12-08-2012, 07:34 PM
  4. Meger multiple file but header not same
    By rocky in forum Excel Help
    Replies: 14
    Last Post: 10-25-2012, 09:09 PM
  5. Excel Macro to Sort Data if a value changes in defined range
    By Rajesh Kr Joshi in forum Excel Help
    Replies: 4
    Last Post: 09-05-2012, 10:31 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •