title: Excel vba Sorting Criteria –different orientations
body: <p>I have a macro for sorting entries in four different sheets. Two of these I want to sort oriented left to right, while the other two must be sorted top to bottom. Right now the code looks roughly as follows (don’t mind "MyRange” and “OtherRange” – they are variables decided outside this code): </p>
  
  <pre><code>        If MySheet.Name = "Shippers" _
          Or MySheet.Name = "Consignees" _
          Then
              MySheet.sort.SortFields.Clear
              MySheet.sort.SortFields.Add Key:=Range("MyRange”), _
              SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
          With MySheet.sort
              .SetRange Range(“OtherRange”)
              .Header = xlGuess
              .MatchCase = False
              .Orientation = xlLeftToRight '&lt;---
              .SortMethod = xlPinYin
              .Apply
          End With
  
          Else
              MySheet.sort.SortFields.Clear
              MySheet.sort.SortFields.Add Key:=Range("MyRange”), _
              SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
          With MySheet.sort
              .SetRange Range(“OtherRange”)
              .Header = xlGuess
              .MatchCase = False
              .Orientation = xlTopToBottom '&lt;---
              .SortMethod = xlPinYin
              .Apply
          End With
          End If
  </code></pre>
  
  <p>The only real difference between the two blocks is the “.Orientation” – row. My question is: Is there any way to merge these two blocks and set “.Orientation” to either xlTopToBottom or xlLeftToRight  depending on the sheet name?</p>