title: How to sort columns in Excel programmatically using vb.net?
body: <p>we are generating an Excel report and we need to sort the data programmatically before saving the file.</p>
  
  <p>Is it possible to sort a specific column of an Excel file programmatically using vb.net?</p>
  
  <p>As per your suggestion, in order to generate excel report with sorting on specific column I just implemented the logic as below..</p>
  
  <pre><code>Dim MyRange As Excel.Range
    gobjExcelReportSheet.Activate()
        MyRange = gobjExcelReportSheet.Range("A8", "L8")
        MyRange.Select()
        MyRange.Sort(Key1:=MyRange.Range("L8"), _
                     Order1:=XlSortOrder.xlAscending, _
                     Header:=XlYesNoGuess.xlGuess, _
                     MatchCase:=False, _
                     Orientation:=XlSortOrientation.xlSortColumns)
  </code></pre>
  
  <p>I tried this logic just before saving the file and even just after saving the file but it is not giving any result i.e. with sorting result or even I am not getting any error.</p>
  
  <p>But the following code works....</p>
  
  <p>gobjExcelReportSheet.Application.Selection.Autofilter()</p>
  
  <p>But there is no option for sorting programmetically.</p>
  
  <p>Please help me...</p>
  
  <p>Thanks!</p>