title: Is there a neat and tidy way to reorder columns in an excel table with VBA?
body: <p>EDIT: Ended up just loading the whole thing into an array and printing the columns in the order i want</p>
  <p>Currently I use the following code to reorder columns in an excel table in VBA. Crucially i must maintain the formatting of the table. The way it works currently is the desired order is loaded into an array and than searching through the table for that header. when its found cut and insert the columns to the far right of the table. Eventually the columns will be an order. However the code runs very slow and it feels like a really dirty way to do it. I was wondering if there is a cleaner way. Ideally i would like to eliminate the use of the clipboard however that is not important.</p>
  <p>The 3 goals for this were to maintain the table formatting, handle missing columns, and handle extra columns. Extra columns naturally end up on the right.</p>
  <p>Any help is appreciated</p>
  <pre><code>Private Sub ColumnArranger
      Dim CorrectOrder As Variant
      Dim i As Variant
      Dim tblComp As ListObject
  
      Set tblComp = ActiveSheet.ListObjects(&quot;BOM_Component_DONE&quot;) 'assigns table on completed sheet to variable
      CorrectOrder = Array(&quot;No.&quot;, &quot;Description&quot;, &quot;HTS&quot;, &quot;Unit Cost&quot;, &quot;TOTAL QTY&quot;, &quot;TOTAL COST&quot;, &quot; Currency&quot;, &quot;Item - Vendor No.&quot;) 'this should be the desired order
      
      On Error Resume Next
      For Each i In CorrectOrder
          Columns(tblComp.ListColumns(i).Range.Column).Cut
          Columns(tblComp.ListColumns.Count + 1).Insert Shift:=xlToRight
      Next i
      On Error GoTo 0
      
  
  End Sub
  </code></pre>