+ Reply to Thread
Results 1 to 7 of 7

Macro - copy and insert multiple rows

  1. #1
    Registered User
    Join Date
    03-20-2013
    Location
    Washington, DC
    MS-Off Ver
    Excel 2010
    Posts
    4

    Post Macro - copy and insert multiple rows

    Hi! Just joined this forum - very excited that someone may be able to help me with my issue.

    I work with hotels and I am trying to create a macro that breaks up data from one row into multiple rows. In my original spreadsheet, each row has a hotel name, code, city, country, etc. Then it has a list of blackout start and end dates. The max number of date ranges is 10.

    I want the macro to look at the number of blackout ranges for each hotel and then insert the same number of additional rows beneath the first row. There should be a separate row for each set of blackout dates.

    I've attached a sample: Tab 1 has my starting data and tab 2 has the desired output. If the hotel has no blackout dates, no new rows would be added. If there is only one blackout date, no new rows would be added either.

    Any suggestions would be greatly appreciated! Let me know if there are any questions.
    Attached Files Attached Files

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Macro - copy and insert multiple rows

    After the row is inserted, do you want the data from columns A to G to be copied to the inserted row along with the corresponding start and end date?

    And then do you want the data to be cleared from the start and end date column in the original row?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    03-20-2013
    Location
    Washington, DC
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Macro - copy and insert multiple rows

    Hi!
    Exactly. If there are multiple sets of blackout dates for a hotel, I'd like the data from A to G to be copied into the inserted rows and for each row to only display one set of blackout dates (start and end). Each row, including the first row, would only display one set of start and end dates.

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Macro - copy and insert multiple rows

    Sorry - i didnt see your 2nd tab showing the required output -Try this code
    Please Login or Register  to view this content.
    Copy the Excel VBA code
    Select the workbook in which you want to store the Excel VBA code
    Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
    Choose Insert | Module
    Where the cursor is flashing, choose Edit | Paste

    To run the Excel VBA code:
    Choose View | Macros
    Select a macro in the list, and click the Run button

  5. #5
    Registered User
    Join Date
    03-20-2013
    Location
    Washington, DC
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Macro - copy and insert multiple rows

    Yes! This is so great! So sorry to do this, but I realized that i omitted a couple of columns that need to be incorporated - can I just change the column names in the formula?

    In case you can help, I've attached the revised spreadsheet and desired output on tab 2. I need a blank column in column C and I am supposed to have a field before each set of start and end dates with the Name of the blackout range. The new columns are highlighted in Yellow.

    I cannot believe how simple your macro formula looks, I was all over the place before I came to this forum. THANK YOU!!!
    Attached Files Attached Files

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Macro - copy and insert multiple rows

    Try this code
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    03-20-2013
    Location
    Washington, DC
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Macro - copy and insert multiple rows

    Perfection! I can't thank you enough. You have saved me so much time and stress. Have a great day.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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