+ Reply to Thread
Results 1 to 5 of 5

VBA/Macro to Duplicate Rows

  1. #1
    Registered User
    Join Date
    07-15-2013
    Location
    Sussex England
    MS-Off Ver
    Excel 2010
    Posts
    2

    VBA/Macro to Duplicate Rows

    Hi,

    I have been searching for several days now and have been unable to find a VBA coding for the following, does anyone have the answer to this or is it even possible?:

    Example:
    I have a spreadsheet that has data in columns A to G and what I need to do is duplicate a row twice to the bottom of the data where the value of column E equals X then I need a formula attached to duplicate row 1 as the value of column G times 92%
    and then for duplicate row 2 as the value of Column G times 8% then I would like to delete the original entry.

    Thanks,
    SH

  2. #2
    Forum Contributor
    Join Date
    08-08-2005
    Location
    Kansas, USA
    MS-Off Ver
    2016
    Posts
    293

    Re: VBA/Macro to Duplicate Rows

    Let me see if I understand:
    You have data in several rows (assume 10 for this example) covering columns A:G.

    If E1 = X then you want A1:G1 copied to A11:G11 and each value A11:G11 multiplied by .92 * G11, AND A1:G1 copied to A12:G12 and multiplied by .08 * G12 Then Delete row 1 (remove the entire row, not just the values); If E1<>X then skip this row. Then repeat for the remaining rows (either rows 2-10 or 1-9 if deleted row 1)?
    Last edited by gjcase; 07-15-2013 at 09:07 AM.

  3. #3
    Registered User
    Join Date
    07-15-2013
    Location
    Sussex England
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: VBA/Macro to Duplicate Rows

    Hi gjcase,

    Yes that is exactly what I am looking for, the below data maybe explains it more clearly.

    Original Data:

    2 0 1 20 4200000 UK 5000
    2 0 1 20 4210000 UK 4000
    2 0 1 20 4220000 UK 3000
    2 0 1 20 4230000 UK 2000
    2 0 1 20 4240000 UK 100

    Result (Assuming That 420000 code is the one code needing duplicates)

    2 0 1 20 4210000 UK 4000
    2 0 1 20 4220000 UK 3000
    2 0 1 20 4230000 UK 2000
    2 0 1 20 4240000 UK 100
    2 0 1 20 4200000 UK 4600
    2 0 1 20 4200000 UK 400

    Thanks,
    SH

  4. #4
    Forum Contributor
    Join Date
    08-08-2005
    Location
    Kansas, USA
    MS-Off Ver
    2016
    Posts
    293

    Re: VBA/Macro to Duplicate Rows

    Try this:

    Please Login or Register  to view this content.
    This does the calculations in matrices, then deletes the original range & overwrites with the Results matrix. It requires that you select the original data first.
    Last edited by gjcase; 07-15-2013 at 10:04 AM. Reason: revised code to account for non-numeric entries

  5. #5
    Forum Contributor
    Join Date
    08-08-2005
    Location
    Kansas, USA
    MS-Off Ver
    2016
    Posts
    293

    Re: VBA/Macro to Duplicate Rows

    After reading your post wiith the data, this does the job a bit better:

    Please Login or Register  to view this content.
    Note however, that it does not put the new rows at the end; rather it substitutes for the original in place. If you want it at the end, we can do that as well.

    If X may be something other than a number, change "Dim X as Double" to "Dim X as Variant"
    Last edited by gjcase; 07-15-2013 at 03:11 PM.

+ 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. A Macro that searches for duplicate rows
    By nenadmail in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-06-2012, 11:02 AM
  2. [SOLVED] deleting duplicate rows macro
    By mike02 in forum Excel General
    Replies: 7
    Last Post: 08-01-2012, 11:10 AM
  3. macro for deleting duplicate rows...
    By WyomingNewb in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-14-2011, 01:15 PM
  4. Macro to create duplicate rows
    By Q-D in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-19-2009, 03:40 PM
  5. [SOLVED] Macro to copy duplicate rows (not delete)
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-19-2005, 08:06 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