ThrottleWorks
Excel Ninja
Hi,
I am using below mentioned code to re-arrange data in a worksheet.
This way, I am sure that the columns will be in a particular order before applying in code.
Can anyone please suggest me a better solution, please note, I am not facing any issue due this, it is not urgent for me.
I am using below mentioned code to re-arrange data in a worksheet.
This way, I am sure that the columns will be in a particular order before applying in code.
Can anyone please suggest me a better solution, please note, I am not facing any issue due this, it is not urgent for me.
Code:
Sub Re_Arrange_Columns()
Dim HeaderRng As Range
Dim DeleteBook As Workbook
Dim DeleteSht As Worksheet
Dim rng As Range
RawBook.Activate
Set HeaderRng = MapSht.Range(MapSht.Cells(2, 1), MapSht.Cells(55, 1)) ‘This is where column headers are stored
RawSht.Cells.Copy ‘this is the workbook I am trying to re-arrange
Workbooks.Add
Range("A1").PasteSpecial xlPasteAll
Set DeleteBook = ActiveWorkbook
Set DeleteSht = ActiveSheet
RawSht.Cells.Clear
Dim ColCount As Long
ColCount = 0
For Each rng In HeaderRng
ColCount = ColCount + 1
Cells.Find(What:="" & rng, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.EntireColumn.Copy
RawSht.Cells(1, ColCount).PasteSpecial xlPasteAll
Next rng
DeleteBook.Close
End Sub