ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Rearrange columns using VBA (https://www.excelbanter.com/excel-programming/334701-rearrange-columns-using-vba.html)

ktpack[_5_]

Rearrange columns using VBA
 

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.


--
ktpack
------------------------------------------------------------------------
ktpack's Profile: http://www.excelforum.com/member.php...o&userid=12167
View this thread: http://www.excelforum.com/showthread...hreadid=387640


Losse[_21_]

Rearrange columns using VBA
 

Do they always have the same labels at the top?


--
Losse
------------------------------------------------------------------------
Losse's Profile: http://www.excelforum.com/member.php...o&userid=24813
View this thread: http://www.excelforum.com/showthread...hreadid=387640


ktpack[_7_]

Rearrange columns using VBA
 

Yes. Do you have an idea

--
ktpac
-----------------------------------------------------------------------
ktpack's Profile: http://www.excelforum.com/member.php...fo&userid=1216
View this thread: http://www.excelforum.com/showthread.php?threadid=38764


Losse[_22_]

Rearrange columns using VBA
 

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

--
Loss
-----------------------------------------------------------------------
Losse's Profile: http://www.excelforum.com/member.php...fo&userid=2481
View this thread: http://www.excelforum.com/showthread.php?threadid=38764


ktpack[_8_]

Rearrange columns using VBA
 

I get a syntax error with this line:

Selection.Name = End


--
ktpack
------------------------------------------------------------------------
ktpack's Profile: http://www.excelforum.com/member.php...o&userid=12167
View this thread: http://www.excelforum.com/showthread...hreadid=387640


Losse[_23_]

Rearrange columns using VBA
 

Selection.Name = "End"

The same needs to be done for the others. Sorry. :-P


--
Losse
------------------------------------------------------------------------
Losse's Profile: http://www.excelforum.com/member.php...o&userid=24813
View this thread: http://www.excelforum.com/showthread...hreadid=387640


ktpack[_10_]

Rearrange columns using VBA
 

oh. duh. i feel dumb for not figuring that one out myself. thanks

--
ktpac
-----------------------------------------------------------------------
ktpack's Profile: http://www.excelforum.com/member.php...fo&userid=1216
View this thread: http://www.excelforum.com/showthread.php?threadid=38764


drdavidge[_3_]

Rearrange columns using VBA
 

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?


--
drdavidge
------------------------------------------------------------------------
drdavidge's Profile: http://www.excelforum.com/member.php...o&userid=36168
View this thread: http://www.excelforum.com/showthread...hreadid=387640



All times are GMT +1. The time now is 05:20 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com