I wrote a truly rudimentary Excel macro to copy the selected row twice, then move the cursor down 3 rows to repeat the process again.
So, if I have a file in which the first 10 lines need to be repeated twice, I run the macro 10 times.
This will save me a ton of keystrokes already, but I'm sure it can be written better, so I just select the first 10 lines and then run the macro once.
Here is what I still have:
Sub Copy_Twice() ' Copies current row twice ActiveCell.EntireRow.Select Selection.Copy Selection.Insert Shift:=xlDown ActiveCell.EntireRow.Select Selection.Copy Selection.Insert Shift:=xlDown ActiveCell.Offset(rowOffset:=3).Select End Sub
For each file I run this macro, it may not be the first 10 lines that need to be copied.
In fact, an even better macro would be to copy each row twice if the cell in column J is empty.
Update. The file has a header row with values ββfor columns A to X. The rows to be copied will be the first x # rows after the header, where column J is empty. Therefore, in one example, lines 2-11 need to be duplicated twice. But in another file it can be lines 2-21.
vba excel-vba copy excel
wongnog
source share