+ Reply to Thread
Results 1 to 4 of 4

Duplicate Rows based on cell value

Hybrid View

Reverend Duplicate Rows based on cell... 05-20-2014, 09:09 AM
Miroslav R. Re: Duplicate Rows based on... 05-20-2014, 09:46 AM
MickG Re: Duplicate Rows based on... 05-20-2014, 09:53 AM
Reverend Re: Duplicate Rows based on... 05-20-2014, 11:06 AM
  1. #1
    Registered User
    Join Date
    05-19-2014
    Posts
    6

    Duplicate Rows based on cell value

    I have seen code for this but can't get it to work. Keep trying code but getting errors I don't know how to fix.

    Trying to solve an issue for a non-profit

    They have raffle ticket sales in Column E. So if a person buys 1 ticket they can just print out a card for them, but if they buy 10 tickets I need to get Excel to produce 9 duplicate rows, so the person has 10 total rows.

    Thanks for any help
    Attached Files Attached Files
    Last edited by Reverend; 05-20-2014 at 09:25 AM. Reason: Added Modified File

  2. #2
    Valued Forum Contributor Miroslav R.'s Avatar
    Join Date
    05-16-2013
    Location
    NMnV, Slovakia
    MS-Off Ver
    Excel 2007
    Posts
    479

    Re: Duplicate Rows based on cell value

    Hi there,
    here is the code:
    Option Explicit
    Sub DuplicateTickets()
    Dim sht As Worksheet
    Dim Xrow, NewRows As Integer
    
    Set sht = Sheets("Sheet1")
    Xrow = 1
    Do Until sht.Cells(Xrow, 1) = ""
      If sht.Cells(Xrow, 5) > 1 Then
        NewRows = sht.Cells(Xrow, 5) - 1
        sht.Cells(Xrow + 1, 1).Resize(NewRows, 1).EntireRow.Insert
        sht.Cells(Xrow, 1).Resize(1, 4).Copy
        sht.Cells(Xrow + 1, 1).Resize(NewRows, 4).PasteSpecial Paste:=xlPasteAll
        Application.CutCopyMode = False
        sht.Cells(Xrow, 5).Resize(NewRows + 1, 1) = 1
        Xrow = Xrow + NewRows
      End If
      Xrow = Xrow + 1
    Loop
    End Sub
    And Your file:
    Untitled 1.xls

    Hope it helps
    Regards
    Miroslav R.

    (If You like my solutions, feel free to add reputation.)

  3. #3
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: Duplicate Rows based on cell value

    Try this:-
    Sub MG20May51
    Dim Lst As Long
    Dim n As Long
    Lst = Range("A" & Rows.Count).End(xlUp).Row
    Application.ScreenUpdating = False
    For n = Lst To 1 Step -1
     With Range("A" & n)
        If .Offset(, 4) > 1 Then
            .Offset(1).Resize(.Offset(, 4) - 1).EntireRow.Insert shift:=xlDown
            .Offset(1).Resize(.Offset(, 4) - 1, 5).Value = .Resize(, 5).Value
        End If
     End With
    Next n
    Application.ScreenUpdating = True
    End Sub
    Regards Mick

  4. #4
    Registered User
    Join Date
    05-19-2014
    Posts
    6

    Re: Duplicate Rows based on cell value

    Thanks. Saved a ton of time. Much appreciated

+ 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. duplicate rows based on cell value
    By epi in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 08-05-2014, 11:33 AM
  2. [SOLVED] Delete rows based on duplicate cell, but leaving first and last duplicate.
    By LadyNicole in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-28-2013, 05:07 AM
  3. Merge rows based on duplicate cell
    By skacutter in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 10-15-2010, 09:47 AM
  4. Duplicate Rows based on cell values
    By rifitintaken in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-20-2010, 09:54 AM
  5. Re: Delete rows based on duplicate and cell color
    By Jsin in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-15-2010, 08:38 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