title: VBA code to sort multiple columns by column name, differing locations
body: <p>I am new to VBA coding and would like a VBA script that sorts multiple columns. I first sort column F from smallest to largest, and then sort column K. However, I would like the Range value to be dynamic based on the column name rather than location (i.e. the value in column F is called "Name", but "Name" won't always be in column F) </p>
  
  <p>I'm looking to change all of the Range values in the macro, and am thinking of replacing it with a FIND function, am I on the right track? </p>
  
  <p>I.e. Change Range _
          ("F1:F10695") </p>
  
  <p>to something like <code>Range (Find(What:="Name", After:=ActiveCell, LookIn:=xlFormulas, _
          LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
          MatchCase:=False, SearchFormat:=False).Activate
      Range(Selection, Selection.End(xlDown)).Select</code></p>
  
  <p>I have also seen some VBA script templates that use the Dim and Set functions to create lists, i.e. set x="Name", then sort for X in the matrix. Is that a better approach? Thank you for your help, I've attached the basic VBA script template below</p>
  
  <pre><code>Sub Macro2()
  '
  ' Macro2 Macro
  '
  
  '
      Selection.AutoFilter
      Range("F1").Select
      ActiveWorkbook.Worksheets("Sheet1").AutoFilter.Sort.SortFields.Clear
      ActiveWorkbook.Worksheets("Sheet1").AutoFilter.Sort.SortFields.Add Key:=Range _
          ("F1:F10695"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
          xlSortNormal
      With ActiveWorkbook.Worksheets("Sheet1").AutoFilter.Sort
          .Header = xlYes
          .MatchCase = False
          .Orientation = xlTopToBottom
          .SortMethod = xlPinYin
          .Apply
      End With
      Range("K1").Select
      ActiveWorkbook.Worksheets("Sheet1").AutoFilter.Sort.SortFields.Clear
      ActiveWorkbook.Worksheets("Sheet1").AutoFilter.Sort.SortFields.Add Key:=Range _
          ("K1:K10695"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
          xlSortNormal
      With ActiveWorkbook.Worksheets("Sheet1").AutoFilter.Sort
          .Header = xlYes
          .MatchCase = False
          .Orientation = xlTopToBottom
          .SortMethod = xlPinYin
          .Apply
      End With
  End Sub
  </code></pre>