Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata

https://stackoverflow.com/questions/52794469/excel-vba-swapping-columns-of-a-vba-range-without-a-loop

Public Sub SwapCols(ColOne As Integer, ColTwo As Integer)
 Dim arr As Variant
 'Dim ColOne As Integer, ColTwo As Integer
 'ColOne = 4
 'ColTwo = 5
 Set arr = Nothing
 arr = Columns(ColOne).Value
 Columns(ColOne) = Columns(ColTwo).Value
 Columns(ColTwo) = arr
End Sub
Public Sub Test_SwapCols()
 Dim ColOne As Integer, ColTwo As Integer
 ColOne = 1
 ColTwo = 2
 Call SwapCols(ColOne, ColTwo)
End Sub
  • No labels