Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've made some changes and adjusted <em>Francis Dean's</em> answer: </p> <ul> <li>For those on Office 2013 (or 2010?), Excel needs to know explicitly that "Sheet1" is the name of a Sheet. </li> <li>Also I adapted the macro for more columns and rows. For example <code>currentRow</code> is <code>Long</code> and the last row being <code>Integer+1</code>. </li> <li>My integer value to determine duplicating is in "J".</li> </ul> <p>The macro is then:</p> <pre><code>Sub DuplicateRows() Dim currentRow As Long Dim currentNewSheetRow As Long: currentNewSheetRow = 1 For currentRow = 1 To 32768 'The last row of your data Dim timesToDuplicate As Integer timesToDuplicate = CInt(Worksheets("Sheet1").Range("J" &amp; currentRow).Value) Dim i As Integer For i = 1 To timesToDuplicate Worksheets("Sheet2").Range("A" &amp; currentNewSheetRow).Value = Worksheets("Sheet1").Range("A" &amp; currentRow).Value Worksheets("Sheet2").Range("B" &amp; currentNewSheetRow).Value = Worksheets("Sheet1").Range("B" &amp; currentRow).Value Worksheets("Sheet2").Range("C" &amp; currentNewSheetRow).Value = Worksheets("Sheet1").Range("C" &amp; currentRow).Value Worksheets("Sheet2").Range("D" &amp; currentNewSheetRow).Value = Worksheets("Sheet1").Range("D" &amp; currentRow).Value Worksheets("Sheet2").Range("E" &amp; currentNewSheetRow).Value = Worksheets("Sheet1").Range("E" &amp; currentRow).Value Worksheets("Sheet2").Range("F" &amp; currentNewSheetRow).Value = Worksheets("Sheet1").Range("F" &amp; currentRow).Value Worksheets("Sheet2").Range("G" &amp; currentNewSheetRow).Value = Worksheets("Sheet1").Range("G" &amp; currentRow).Value Worksheets("Sheet2").Range("H" &amp; currentNewSheetRow).Value = Worksheets("Sheet1").Range("H" &amp; currentRow).Value Worksheets("Sheet2").Range("I" &amp; currentNewSheetRow).Value = Worksheets("Sheet1").Range("I" &amp; currentRow).Value currentNewSheetRow = currentNewSheetRow + 1 Next i Next currentRow End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload