title: Macro to sort multiple tables on two criteria
body: <p>I have tried in vain to get the below macro to run correctly. The end goal is a macro that will sort multiple tables (on a single worksheet) based on two criteria, and which will also work on whatever worksheet is active. I can make a macro with exact table references, but seek something more agile to avoid having a macro for each worksheet.</p>
  
  <p>The bulk of my code draws from Doug Glancy's recommendation in <a href="https://stackoverflow.com/questions/16837547/using-a-macro-to-sort-multiple-tables-based-on-the-same-column">this post</a>, but it doesn't run properly (as the original poster noted before the thread died). The macro runs without errors but doesn't actually sort any of the data.</p>
  
  <p>I think the broken portion is the <code>Key:=lo.ListColumns("Name of table column").Range</code> part. I am not familiar enough with that syntax to troubleshoot it.</p>
  
  <p>I appreciate any suggestions or alternatives! Also, let me know if my requirements are unclear at all.</p>
  
  <pre><code>Sub CustomSort()
  Dim lo As Excel.ListObject
  Dim ws As Excel.Worksheet
  
  Set ws = ActiveSheet
  For Each lo In ws.ListObjects
      With lo.Sort
          .SortFields.Add Key:=lo.ListColumns("Status").Range, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
          .SortFields.Add Key:=lo.ListColumns("Inventory Number").Range, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
          .Header = xlYes
          .Apply
      End With
  Next lo
  End Sub
  </code></pre>