PDA

View Full Version : Solved: Rearrange columns



austenr
05-25-2006, 06:20 AM
Is there a way to rearrange columns? I have a spreadsheet with many columns and some of them should be grouped next to each other but are not. This makes it difficult to hunt for what you need. For instance, First Name, Middle Name and Last Name are spread out in varying places in the spreadsheet. Is ther a way to rearrange them so they can be next to one another? :dunno

lucas
05-25-2006, 06:27 AM
are you wanting to do a vba sort or do you just need to manually move them one time?

to manually move them just select the column letter which selects the entire column then cut them and select the entire column you wish to insert them in front of and right click and click on insert cut cells...not sure what your looking for.

austenr
05-25-2006, 06:59 AM
Was hoping for a VBA approach.

mvidas
05-25-2006, 07:19 AM
Austen, 'How to move column "D" to before column "B"
Columns("D").Cut
Columns("B").InsertMatt

lucas
05-25-2006, 07:19 AM
from a simple search of the forum:
http://www.vbaexpress.com/forum/showthread.php?t=6252&highlight=sort+columns
Still not sure what your looking for?

mdmackillop
05-25-2006, 07:58 AM
As I had a few minutes spare.

Sub MoveColumns()
Dim Cols As String, Source As String, Target As String
Cols = InputBox("Enter column letter(s) to move and target column" & vbCr _
& "eg 'E:F,B' or 'F,B'", "Help Austen to move columns")
If Cols = "" Then Exit Sub
If InStr(1, Cols, ",") = 0 Then
MsgBox "Enter comma between letters"
Exit Sub
End If
Source = Split(Cols, ",")(0)
On Error Resume Next
'Fix semi colons
Source = Replace(Source, ";", ":")
Target = Split(Cols, ",")(1)
Columns(Source).Cut
Columns(Target).Insert
End Sub

austenr
05-25-2006, 08:21 AM
Great Malcomb, just what I needed. I know the order I want them to be in so a sub would do the trick. I can get it from here. Thanks a bunch. Consider this solved.