VBA Column Inversion
Solved
texastina
Posted messages
55
Status
Member
-
texastina Posted messages 55 Status Member -
texastina Posted messages 55 Status Member -
Hello,
I would like to know if it is possible to reverse the contents of several columns using VBA?
For example: Column D ==> Column B
Column B ==> Column C
Column C ==> Column D
I hope I was clear enough :)
Thank you for your responses :)
I would like to know if it is possible to reverse the contents of several columns using VBA?
For example: Column D ==> Column B
Column B ==> Column C
Column C ==> Column D
I hope I was clear enough :)
Thank you for your responses :)
4 answers
-
Hello
I prefer to move the column
example:Sub MoveCol() Columns(4).Cut Columns(2).Insert Shift:=xlToRight Range("A1").Select End Sub
See you +
Maurice -
Hello,
Yes, it is possible. You can even limit yourself to the first move: column D in front of column B.
The other columns will automatically be in the right place.
If beyond your question you want to know how to do it, use the macro recorder and you will have the code.
Best regards -
Hello,
Yes, this is possible thanks to the copy and paste command sequence.
In your case:dim example as Range // Declaration of your action field example = Range("A1:E600") // Selection of a large range, to be adapted according to the length of your columns. example.Column(4).select // Selects column D Selection.copy // Copies the selected column example.Column(5).select // Selects column E ActiveSheet.Paste // Pastes what has been copied into the selected column
I hope I have been clear enough, do it as you wish :)
Keep me posted if there's anything you don't understand. -
Hello
try:
Option Explicit
'------------------
Sub bcd_cdb()
Dim Derlig As Integer, T_in, T_out, cptr As Integer
Application.ScreenUpdating = False
Derlig = Cells.Find(what:="*", searchdirection:=xlPrevious).Row
T_in = Range("B1:D" & Derlig)
ReDim T_out(1 To Derlig, 1 To 3)
For cptr = 1 To UBound(T_in)
T_out(cptr, 1) = T_in(cptr, 3) '
T_out(cptr, 2) = T_in(cptr, 1) '
T_out(cptr, 3) = T_in(cptr, 2) '
Next
Range("B1").Resize(UBound(T_in), 3) = T_out
End Sub
--
Michel