title: Excel 2013: Sorting columns based on first row value using VBA
body: <p>I would like to implement an Excel macro that sorts all columns from column "C" to the last column containing data (columns A and B shall not be affected).</p>
  
  <p>The columns shall be sorted from A->Z based on the cell value of their first row (which is a string).</p>
  
  <p>So far, I came up with the following code which I do not like that much because it contains hardcoded numbers for the Sort range making the code not really robust.</p>
  
  <pre><code>Sub SortAllColumns()
      Application.ScreenUpdating = False
  
  'Sort columns
      With ActiveWorkbook.Worksheets("mySheet").Sort
          .SetRange Range("C1:ZZ1000")
          .Header = xlYes
          .MatchCase = False
          .Orientation = xlLeftToRight
          .Apply
      End With
  
      Application.ScreenUpdating = True
  End Sub
  </code></pre>
  
  <p>Searching the internet, one may find tons of suggestions getting the last used column or row. However most of them will blow up the code more than I expected.</p>
  
  <p>I am not a VBA expert and it would be great if someone could make a suggestion how this problem can be solved in an elegant and efficient way.</p>
  
  <p>If this is important: We will definitely not have more that 1000 rows and 1000 columns.</p>
  
  <p>Any suggestion is highly appreciated. </p>