+ Reply to Thread
Results 1 to 8 of 8

Need Macro to automatically sort parts of a pasted selection to three different columns

  1. #1
    Registered User
    Join Date
    10-07-2015
    Location
    Italy
    MS-Off Ver
    Office 2007
    Posts
    4

    Need Macro to automatically sort parts of a pasted selection to three different columns

    Hi there!

    I have just recently found out about Excel macros, and I was wondering (being almost completely ignorant on the matter) if there was a way to use macros in order to rearrange copy-pasted data in a specific way. It could really save me a lot of time.

    I am basically copy-pasting data from a website and rearranging it manually: the data consists of 24-Cells clipboards (the original data is not excel, but when I paste it on my sheet, it's automatically arranged in 24 cells all on the same column) that I am currently pasting in, say, Column C, and then manually moving the cells from the 7th to the 12th in Column D, From the 13th to the 18th in Column E, and from the 19th to the 24th in Column F, so that they are all aligned with the first 6.

    Can anyone help with this? I don't have much time to learn macros, so if someone could write it for me and let me reverse-engineer it I would really appreciate it, I literally don't know any of the functions/commands/expressions to use to do any of this...

    Thanks in advance!

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,093

    Re: Need Macro to automatically sort parts of a pasted selection to three different column

    Some variations on a theme:

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    10-07-2015
    Location
    Italy
    MS-Off Ver
    Office 2007
    Posts
    4

    Re: Need Macro to automatically sort parts of a pasted selection to three different column

    Thank you very much, I will try and understand these when I have some free time

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,093

    Re: Need Macro to automatically sort parts of a pasted selection to three different column

    You're welcome. Thanks for the rep.



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  5. #5
    Registered User
    Join Date
    10-07-2015
    Location
    Italy
    MS-Off Ver
    Office 2007
    Posts
    4

    Re: Need Macro to automatically sort parts of a pasted selection to three different column

    Sorry to bring this up again: are the examples provided supposed to work by themselves? They seem to do what's intended... but I should have mentioned the cells I meant were relative to where I pasted the new data. It's a huge document, and the data needs to be split in 6 cells for each column multiple times, not just for exactly the first 6 rows.

    I'm looking up "relative cell positions" and found this, if it's not too much of a bother could anyone tell me how to actually apply this to the macros mentioned above this post? I thought I would just have to replace the arbitrary values with a variable that expresses the "current" selected position and add "+ the arbitrary value" or something (Range.Offset Property I guess?), but this looks different from what I expecte.
    Last edited by Scott Fairbanks; 10-08-2015 at 04:27 AM.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,093

    Re: Need Macro to automatically sort parts of a pasted selection to three different column

    To be fair, the code provided does exactly what you described ... in three different ways. More as an exercise but also to give you the opportunity to see different ways of doing it ... with the expectation that you may want to adapt it and one way might be easier than another.

    The code below will do what you now ask. The setup is a little more complex as it now needs to establish which cell is a) selected and b) to be used as the "base address".

    It should cope with you copying your 24 cell single column range anywhere on the sheet. Simply select any cell within the range and run the macro. Note the caveat in the code regarding blank cells.


    Please Login or Register  to view this content.

    Regards, TMS

  7. #7
    Registered User
    Join Date
    10-07-2015
    Location
    Italy
    MS-Off Ver
    Office 2007
    Posts
    4

    Re: Need Macro to automatically sort parts of a pasted selection to three different column

    Quote Originally Posted by TMS View Post
    To be fair, the code provided does exactly what you described ... in three different ways.
    Indeed, as I said I should have been more clear. Sorry.

    Anyway, this was invaluable help. Thanks a lot again!

    Marking as solved.

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,093

    Re: Need Macro to automatically sort parts of a pasted selection to three different column

    You're welcome.

+ 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. VBA To Sort 2 Columns Automatically
    By dustind8721 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-27-2015, 12:34 PM
  2. Search parts of columns looking for matches in parts of other columns in a row
    By autiger58 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-02-2014, 03:52 AM
  3. [SOLVED] How to automatically sort the columns (move the columns around)
    By OldGrantonian in forum Excel General
    Replies: 4
    Last Post: 08-18-2013, 07:44 AM
  4. Run Macro automatically when data is PASTED into a table
    By tabira in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-17-2012, 08:13 AM
  5. Automatically resize pasted image - Having trouble with selection
    By jerryisgood in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-13-2011, 09:01 AM
  6. Replies: 0
    Last Post: 02-09-2011, 07:13 PM
  7. sort columns with multiple selection
    By krish T in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-06-2010, 05:16 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