+ Reply to Thread
Results 1 to 8 of 8

Row Duplication With Tricky Variables

  1. #1
    Registered User
    Join Date
    01-10-2017
    Location
    UK
    MS-Off Ver
    2013
    Posts
    23

    Row Duplication With Tricky Variables

    Hi there,

    Having had some extremely helpful responses on this forum in the recent past, I thought I'd return for some more Excel Macro/VBA help.

    I've attached an example spreadsheet with the problem.

    1. I work with timetable data sets which are often thousands of rows in length.

    2. Each row in the example spreadsheet represents a booking, but the data is often a mixture of bookings in single and multiple locations. Some rows are designated for only one room, while others contain multiple locations in the "Location" column.

    3. I've been trying to devise an automated method of turning the data as it is in the "Initial Data" tab to how it looks in the "Desired Outcome" tab.

    4. What I need is for a Macro that works through the data, identifying when a booking (i.e. a row ) has multiple locations attributed to it. The macro then needs to copy the entire row, and copy/insert as many rows as are necessary underneath in order to produce one row per location. All of the other data remains the same - it is just the location that needs to be unique in each of the new copied/inserted rows.

    5. The main challenge here is that the locations are often separated by various characters, such as "/" and ",", but can also be separated by other characters as well. If there is no way to produce a macro that can identify which, then a solution that can be easily edited to look for specific characters (defined by the user) between locations would be desirable.


    6. The data is often thousands of rows in length, so the macro needs to continue working until no more data exists to process.


    At its core, this is another (relatively) simple duplication macro, but with some variables (i.e. the number of different locations and the characters separating each location) that make this kind of macro way out of my technical depth. It's all about the "Location" column, with the remaining columns needing simply to be copied identically, with only the Location differing in each resulting duplicated row.

    The manual method for this (text to columns with specified character as delimiter, then copying/pasting the required number of rows below the data, then copying the text-to-columns locations and transpose-pasting them down in the location column) takes way, way too long when there are thousands of rows to work with!

    I appreciate any advice and input on the matter!
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    11-26-2012
    Location
    Sydney
    MS-Off Ver
    2010
    Posts
    419

    Re: Row Duplication With Tricky Variables

    Try this:

    It will replace any /, \, or | with a comma (add more delimeters if needed) so that the split function can separate the Locations into an array. Hope it does what you want!
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    01-10-2017
    Location
    UK
    MS-Off Ver
    2013
    Posts
    23

    Re: Row Duplication With Tricky Variables

    This is almost perfect! I'm having two small problems with this however:

    1. Everything copies as it should in the right order, but the values in the "Binary Weeks" column get butchered, and can't be turned back to their original values, even when formatting as text/number. Is there any way to resolve this? The "Binary Weeks" format in "Initial Data" is essential to the rest of the work I do with the data. It's formatted as "Text" in "Initial Data", but it's "General" in the "Desired OUtcome" sheet after running the Macro. Essentially, I'd like the Binary Weeks number format in "Desired Outcome" to look identical (i.e. 0's and 1's in the correct order) to the format in "Initial Data". As it stands, the Binary Weeks can't be returned to their pre-macro format, even when changing cell format to General/Number etc. This may be my fault for not stressing its importance!

    2. If I wanted to run the Macro from my personal workbook as opposed to a module on this specific workbook, would this be too much of an edit?

  4. #4
    Valued Forum Contributor
    Join Date
    11-26-2012
    Location
    Sydney
    MS-Off Ver
    2010
    Posts
    419

    Re: Row Duplication With Tricky Variables

    This should solve 1. for you (added line for setting Number Format to text). As for 2 - shouldn't be too hard, but getting a bit late here, so I'll have to sleep on it.

    Please Login or Register  to view this content.
    Last edited by mgs73; 01-17-2017 at 11:56 PM.

  5. #5
    Registered User
    Join Date
    01-10-2017
    Location
    UK
    MS-Off Ver
    2013
    Posts
    23

    Re: Row Duplication With Tricky Variables

    This is great. Problem 1. Solved!

    Will wait to hear back about problem 2. Just realised your location - thank you for taking the time!

  6. #6
    Valued Forum Contributor
    Join Date
    11-26-2012
    Location
    Sydney
    MS-Off Ver
    2010
    Posts
    419

    Re: Row Duplication With Tricky Variables

    I've changed it so that it uses the active sheet, and it overwrites the input with the output. I think this should work in a personal workbook - good luck!

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    01-10-2017
    Location
    UK
    MS-Off Ver
    2013
    Posts
    23

    Re: Row Duplication With Tricky Variables

    Again, I can't thank you enough for your help in this matter!

    The code works perfectly, and shall save a great deal of time for me.

    All the Best

  8. #8
    Registered User
    Join Date
    01-10-2017
    Location
    UK
    MS-Off Ver
    2013
    Posts
    23

    Re: Row Duplication With Tricky Variables

    Again, I can't thank you enough for your help in this matter!

    The code works perfectly, and shall save a great deal of time for me.

    All the Best

+ 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. tricky if formula, lots of variables
    By digdig83 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-09-2013, 06:55 PM
  2. [SOLVED] finding an output from 5 variables in an array using exterior input user variables
    By Allsort in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-09-2013, 11:16 AM
  3. Replies: 3
    Last Post: 09-11-2012, 02:03 AM
  4. Tricky Issue w/Changing Variables
    By Dynamo418 in forum Excel General
    Replies: 0
    Last Post: 07-28-2012, 10:06 PM
  5. macro that finds variables in one column and enters values if variables found
    By xln00b in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-07-2010, 08:22 AM
  6. Unzip Code - Works without Variables, Breaks with Variables...
    By AdamParker in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-06-2009, 02:35 PM
  7. Tricky Tricky episode 2!!!
    By mhax in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-21-2006, 10:15 AM
  8. [SOLVED] no duplication please
    By asmenut in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-10-2005, 05:05 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