+ Reply to Thread
Results 1 to 13 of 13

Reposition Columns

  1. #1
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Reposition Columns

    Is there any way to use a macro to repostion columns in a worksheet.

    I've attached a simple example, I basically want to be able to run a macro that will repostion (in this sample) columns B, C and G, so they appear between coulmns E and F? There would need to be an option to reset the columns back to their original position as well. Whilst the colour is simply to highlight the relevant columns, the moved columns would need to maintain any formatting, header colours etc...

    Many thanks
    Attached Files Attached Files
    Last edited by HangMan; 04-30-2015 at 04:32 AM.

  2. #2
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,444

    Re: Reposition Columns

    Hi,

    Does this help?

    Please Login or Register  to view this content.
    Rule 1: Never merge cells
    Rule 2: See rule 1

    "Tomorrow I'm going to be famous. All I need is a tennis racket and a hat".

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Reposition Columns

    This should do
    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Re: Reposition Columns

    Hi jindon,

    Is there any way to maintain the formatting of the columns moved as well, e.g. column width, colour, cell formatting etc?

    Many thanks
    Last edited by HangMan; 04-30-2015 at 10:14 AM.

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Reposition Columns

    Then need to Cut/Paste...
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Re: Reposition Columns

    Hi jindon,

    Amazing, works perfectly... So I can understand it fully can you explain...

    Please Login or Register  to view this content.
    as I need to try and apply this to my main much much larger sheet. I'm trying to fuigure out how ("4,5",2), Array(7,6) relate to the specific columns, and why the 4,5 have "" around the numbers.

    Basically I'm trying to understand where and which numbers go where based on the coulmns I need to move. It made sense on the first version but now I'm slightly confused by the logic.

    Many thanks

  7. #7
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Re: Reposition Columns

    Hi Sweep,

    Yes, this works well too...

    Many thanks

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Reposition Columns

    Please Login or Register  to view this content.
    e holds Array("4,5", 2) and Array(7, 6) as it loops

    Please Login or Register  to view this content.
    e(0) = "4,5" and 7 respectively (1st element of the array)
    e(1) = 2 and 6 (2nd element of the array)

    You want column 5 & 4 to be inserted in column 2 and column 7 to be inserted in column 6.

    HTH

  9. #9
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Re: Reposition Columns

    So my real world example, attached (again slightly simplified, as there are around 80 columns, but no columns to the right of these need to move).

    I need to move columns 2,3,4 and 10, to column 19, so I'd assumed I'd go

    Please Login or Register  to view this content.
    but firstly it only moves columns 2 and 3 and misses out 4 then what is column 10, which becomes column 7 after 2, 3 & 4 have moved ends up in the wrong place. What am I doing wrong?

    Many thanks
    Attached Files Attached Files

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Reposition Columns

    In that case.... one way
    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Re: Reposition Columns

    Hi jindon,

    Okay, that moves the columns to the correct position but then you have to run the macro 41 times to reset them back to their original positions, is it possible for this to be a toggle, run once to move columns, run again to reset them back to their original positions?

    Many thanks

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Reposition Columns

    Toggle...
    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Re: Reposition Columns

    Hi jindon,

    Works perfectly, I love the simplicity of the code, I just wish I understood it a little better. I need to spend some time understanding the logic as VBA isn't my strong point.

    Many thanks for your elegant solution, greatly appreciate the time you've taken over this...

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Macro to reposition values within cells.
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 39
    Last Post: 01-28-2012, 04:55 PM
  2. Reposition Characters Within A Cell
    By christophercdavis in forum Excel General
    Replies: 2
    Last Post: 03-28-2011, 01:05 PM
  3. Reposition screen based on cell Content.
    By emt3000gt in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-12-2007, 02:06 PM
  4. is it to only reposition
    By froggy19 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-21-2007, 03:13 PM
  5. how to reposition a data table in chart
    By JohnBonjer in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 02-06-2006, 07:15 AM

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