+ Reply to Thread
Results 1 to 3 of 3

Rearrange columns - loop perhaps?

  1. #1
    Forum Contributor
    Join Date
    06-15-2011
    Location
    Chester, England
    MS-Off Ver
    Excel 2013
    Posts
    117

    Rearrange columns - loop perhaps?

    The following macro takes information from one sheet and puts it on another (basically swaps the order of the columns):

    Please Login or Register  to view this content.
    It works perfectly, but only if Sheet2 is active - why is this?

    Secondly, I am doing the same operation for around 20 columns - could I turn this into a loop?

    Thanks for reading.
    Last edited by tone640; 10-20-2011 at 09:21 AM.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,102

    Re: Rearrange columns - loop perhaps?

    Please Login or Register  to view this content.
    The underlined part is an unqualified range reference. For code in a normal module, that will always refer to the active sheet, hence Sheet2 needs to be active. It should be:
    Please Login or Register  to view this content.
    It would be simpler, IMO, to use a row above your data, input numbers for the order you want the columns in, then just sort the data left to right instead.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Contributor
    Join Date
    06-15-2011
    Location
    Chester, England
    MS-Off Ver
    Excel 2013
    Posts
    117

    Re: Rearrange columns - loop perhaps?

    I didn't even know you could sort left to right!

    As always your expert assistance is much appreciated.

+ 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