Excel macro 2016 in VBA. Need to copy from 8 separated columns from one sheet to another, in different order. Tried but the Paste is done always in same column A...
Use an array to collect, reshape then return the values.
A,B,C,G,F,R,S,T to sheet TMP in columns A,B,C,D,E,F,G,H
Sub Button1_Click()
Dim i As Long, arr as variant
with workSheets("Validation by rules")
'collect
i= .Cells(.Rows.Count, 1).End(xlUp).Row
arr = .range(.cells(1,"A"), .cells(i, "T")).value
'reshape part 1
for i=lbound(arr, 1) to ubound(arr, 1)
arr(i, 4) = arr(i, 7)
arr(i, 5) = arr(i, 6)
arr(i, 6) = arr(i, 18)
arr(i, 7) = arr(i, 19)
arr(i, 8) = arr(i, 20)
next i
end with
'reshape part 2
redim preserve arr(lbound(arr, 1) to ubound(arr, 1), lbound(arr, 2) to 8)
'return
workSheets("TMP").cells(1,1).resize(ubound(arr, 1), ubound(arr, 2)) = arr
end sub