Rearrange columns using VBA

K

ktpack

I know that i can just record a macro that moves columns around.
However, I want one that allows me to put them in a certain order based
on criteria i define. For example, my columns might sometimes come into
my spreadsheet as B,C,D,A,G,H,I,F and other times as F,B,C,A,D,E,H,I.
How can I create a macro that reorganizes them after they've come in? i
don't want them to show alphabetically, i just want them to show in the
order that I designate.

Any help would be appreciated. I am fairly new at this and am tired of
jerry-rigging things to make them appear to work.
 
L

Losse

Sure. If column A is supposed to be "Aaa" do:

Range("A1").Select
Do Until ActiveCell.Value = Aaa
ActiveCell.Offset(0, 1).Select
Loop
Selection.Name = Start
Do While ActiveCell <> ""
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Offset(-1, 0).Select
Selection.Name = End
Do While ActiveCell <> ""
ActiveCell.Offset(0, -1).Select
Loop
Selection.Name = End2
Range("A1").Select
Selection.EntireColumn.Insert
Range("Start:End").Select
Selection.Copy
Range("A1:End2").Select
ActiveSheet.Paste


Just be sure to change the names for each of them. I'm sure there ar
much easier ways to do this, but this is the only way that comes t
mind
 
D

drdavidge

Anyone have any easier ways to do this? I need to rearange about 30-40
columns and insert blank ones at specific points based on the column
header name. Any ideas?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top