+ Reply to Thread
Results 1 to 8 of 8

Rearrange columns using VBA

  1. #1
    Registered User
    Join Date
    07-23-2004
    Posts
    7

    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.

  2. #2
    Registered User
    Join Date
    06-30-2005
    Posts
    61
    Do they always have the same labels at the top?

  3. #3
    Registered User
    Join Date
    07-23-2004
    Posts
    7
    Yes. Do you have an idea?

  4. #4
    Registered User
    Join Date
    06-30-2005
    Posts
    61
    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 are much easier ways to do this, but this is the only way that comes to mind.

  5. #5
    Registered User
    Join Date
    07-23-2004
    Posts
    7
    I get a syntax error with this line:

    Selection.Name = End

  6. #6
    Registered User
    Join Date
    06-30-2005
    Posts
    61
    Selection.Name = "End"

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

  7. #7
    Registered User
    Join Date
    07-23-2004
    Posts
    7
    oh. duh. i feel dumb for not figuring that one out myself. thanks!

  8. #8
    Registered User
    Join Date
    07-07-2006
    MS-Off Ver
    Excel 2007
    Posts
    60
    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?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1