+ Reply to Thread
Results 1 to 4 of 4

VBA script to copy and order strings based on a key value, code doesn't seem to run

  1. #1
    Registered User
    Join Date
    10-19-2023
    Location
    Netherlands
    MS-Off Ver
    2309
    Posts
    3

    VBA script to copy and order strings based on a key value, code doesn't seem to run

    I have 2 files. In file 1 I have certain strings in column A. In column D, I have team numbers in the format Team 1 (example). The teams go from 1 to 19, and the order of teams is randomized.
    In file 2 I have team numbers in column D, except here the team numbers are formatted as Team_361948_1_TBL2324. The number 1 indicates that this is team 1. This is about the same teams as file 1, just a different notation. Here, the team numbers are ordered from team 1 (top) to team 19 (bottom). Every team is supposed to have a maximum of 7 members, so in column D of file 2 you first have 7 times Team_361948_1_TBL2324, then 7 times Team_361948_2_TBL2324, etc.

    What I want to do is copy the student numbers from file 1 to file 2, except I also want them to correspond to the correct team indicated by column D. So the order of the student numbers needs to be changed based on the team they belong to, as indicated in file 1. I'm trying to do this with a VBA script, but I don't really know what I'm doing. Could anyone please take a look at the code I have so far and tell me what I'm messing up here? Thanks in advance! Code is attached.
    Attached Files Attached Files
    Last edited by KBosch; 10-19-2023 at 07:51 AM.

  2. #2
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: VBA script to copy and order strings based on a key value, code doesn't seem to run

    see big yellow banner - upload your actual workbooks (de-sensitized if necessary) - you are likely to get an in-context solution as we would be able to test which we cannot do with just a text file.
    Torachan,

    Mission statement; Promote the use of Tables, Outlaw the use of 'merged cells' and 'RowSource'.

  3. #3
    Registered User
    Join Date
    10-19-2023
    Location
    Netherlands
    MS-Off Ver
    2309
    Posts
    3

    Re: VBA script to copy and order strings based on a key value, code doesn't seem to run

    Thanks for your reply, I just added the two files without any unnecessary info.

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA script to copy and order strings based on a key value, code doesn't seem to run

    Place this macro in File2. Make sure that both workbooks are open. Run the macro.
    Please Login or Register  to view this content.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

+ 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. [SOLVED] Copy code doesn't stop at the end of the data
    By Frankie_The_Flyer in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-24-2019, 06:20 PM
  2. [SOLVED] Code doesn't copy the data without any errors
    By PaulM100 in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 07-15-2019, 11:28 AM
  3. [SOLVED] Why does this code doesn't copy a simple Matrix?
    By Noon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-19-2015, 05:06 AM
  4. [SOLVED] New Code Copy Doesn't Work properly
    By Kyle123 in forum Suggestions for Improvement
    Replies: 3
    Last Post: 07-18-2012, 08:00 AM
  5. Copy a new worksheet and the code doesn't work.
    By Wayne555 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-20-2010, 09:28 AM
  6. Copy + Paste doesn't work when I run this code...
    By wildjester in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-21-2009, 03:57 PM
  7. VBA Code for Copy Paste doesn’t work
    By Shark Man in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-16-2009, 02:37 PM

Tags for this Thread

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