title: How to combine two vba codes?
body: <p>I'd like to combine (run) two different vba functions in one sheet. How to do that?</p>
  
  <pre><code>Option Explicit
  Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  'Updateby Extendoffice 20161123
      Dim rgTable As Range
      Dim rgData As Range
      Dim xColumn As Integer
      On Error Resume Next
      Application.ScreenUpdating = False
      Set rgTable = Range("mydata")
      With rgTable
          Set rgData = .Offset(1, 0).Resize(.Rows.Count - 1, .Columns.Count)
          If Not Application.Intersect(ActiveCell, rgData.Cells) Is Nothing Then
              xColumn = ActiveCell.Column - .Column + 1
              If ActiveSheet.AutoFilterMode = False Then
                  .AutoFilter
              End If
              If ActiveSheet.AutoFilter.Filters(xColumn).On = True Then
                  .AutoFilter Field:=xColumn
              Else
                  .AutoFilter Field:=xColumn, Criteria1:=ActiveCell.Value
              End If
          End If
      End With
      Set rgData = Nothing
      Set rgTable = Nothing
      Application.ScreenUpdating = True
  End Sub
  </code></pre>
  
  <p>AND</p>
  
  <pre><code>Public blnToggle As Boolean
  Private Sub Worksheet_BeforeDoubleClick _
      (ByVal Target As Range, Cancel As Boolean)
  'Updateby Extendoffice 20161123
      Dim LastColumn As Long, keyColumn As Long, LastRow As Long
      Dim SortRange As Range
      LastColumn = _
      Cells.Find(What:="*", After:=Range("A1"), _
      SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
      keyColumn = Target.Column
      If keyColumn &gt; LastColumn Then Exit Sub
      Application.ScreenUpdating = False
      Cancel = True
      LastRow = Cells(Rows.Count, keyColumn).End(xlUp).Row
      Set SortRange = Target.CurrentRegion
      blnToggle = Not blnToggle
      If blnToggle = True Then
          SortRange.Sort _
          Key1:=Cells(2, keyColumn), Order1:=xlAscending, Header:=xlYes
      Else
          SortRange.Sort _
          Key1:=Cells(2, keyColumn), Order1:=xlDescending, Header:=xlYes
      End If
      Set SortRange = Nothing
      Application.ScreenUpdating = True
  End Sub
  </code></pre>
  
  <p>Source:
  <a href="https://www.extendoffice.com/documents/excel/4258-excel-click-cell-to-filter.html" rel="nofollow noreferrer">https://www.extendoffice.com/documents/excel/4258-excel-click-cell-to-filter.html</a>
  <a href="https://www.extendoffice.com/documents/excel/4259-excel-click-on-header-to-sort.html" rel="nofollow noreferrer">https://www.extendoffice.com/documents/excel/4259-excel-click-on-header-to-sort.html</a></p>