antman2988
Board Regular
- Joined
- Jun 28, 2018
- Messages
- 78
I have found this piece of code from somewhere else, and I modified it a bit to meet my needs, but I'm not entirely sure how it works. The reason I would like to know how it works is because I would like to modify it further, but I am newer to VBA and do not understand how the Resize, Index, and Evaluate functions work together in this macro.
Any help is appreciated! Thanks!
VBA Code:
Sub RearrangeColumns()
Dim newColumnOrder As Variant
newColumnOrder = Array(1, 2, 3, 4, 41, 42, 43, 44, 5, 6, 49, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46, 47, 48, 50, 51, 52)
Range("A1").Resize(Cells.Find("*", , xlFormulas, , xlRows, xlPrevious).Row, UBound(newColumnOrder) + 1) = Application.Index(Cells, Evaluate("ROW(1:" & Cells.Find("*", , xlFormulas, , xlRows, xlPrevious).Row & ")"), newColumnOrder)
End Sub
Any help is appreciated! Thanks!