Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default duplicate a row with a macro

Hello all,

In excel, I want to write a macro that will do the following.

Lets say I have a sheet with 300 rows

I want to copy the first row, and paste this 180times in a separate worksheet.

Once its done this, move to the second row, and repeat the above, with it
being pasted under what i just did above, until its at the end of all the
rows.

Anyone got a scooby on how to do this!

Cheers

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default duplicate a row with a macro

Hi,

This copes each row in Sheet 1 180 times into sheet 2. Alt +F11 to open Vb
editor. Right click 'This Workbook' and insert module and paste this in. Tap
F5 in VB editor to run it.

Sub copyit()
Dim MyRange As Range
Sheets("Sheet2").Select
lastrow = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
Set MyRange = Sheets("Sheet1").Range("A1:A" & lastrow)
For Each c In MyRange
c.EntireRow.Copy
lastrow2 = Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Row
For x = 0 + lastrow2 To 180 + lastrow2
Cells(x, 1).PasteSpecial
Next
Next
End Sub

Mike

"craig51" wrote:

Hello all,

In excel, I want to write a macro that will do the following.

Lets say I have a sheet with 300 rows

I want to copy the first row, and paste this 180times in a separate worksheet.

Once its done this, move to the second row, and repeat the above, with it
being pasted under what i just did above, until its at the end of all the
rows.

Anyone got a scooby on how to do this!

Cheers

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default duplicate a row with a macro

Sub copy180()

Set oldsht = ActiveSheet
Worksheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Name = "Copy 180"
Set newsht = ActiveSheet

NumberofCopies = 180
OldRowCount = 1
NewRowCount = 1
With oldsht
Do While .Range("A" & OldRowCount) < ""
.Rows(OldRowCount).Copy _
Destination:=newsht.Rows(NewRowCount & ":" & _
(NewRowCount + NumberofCopies - 1))
NewRowCount = NewRowCount + NumberofCopies
OldRowCount = OldRowCount + 1
Loop
End With

End Sub


"craig51" wrote:

Hello all,

In excel, I want to write a macro that will do the following.

Lets say I have a sheet with 300 rows

I want to copy the first row, and paste this 180times in a separate worksheet.

Once its done this, move to the second row, and repeat the above, with it
being pasted under what i just did above, until its at the end of all the
rows.

Anyone got a scooby on how to do this!

Cheers

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default duplicate a row with a macro

Thanking you both, much much appriecated!!!
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Duplicate remover (no macro) RyanR8881 Excel Discussion (Misc queries) 1 October 7th 08 10:38 PM
macro for duplicate values italiavb Excel Worksheet Functions 0 February 7th 07 12:23 AM
Macro - Cut and paste a row if duplicate Dileep Chandran Excel Programming 10 January 4th 07 01:40 AM
Macro to delete duplicate data Tom Harvey Excel Programming 2 June 26th 04 01:36 AM
Macro that controlls duplicate values Emece[_2_] Excel Programming 1 August 26th 03 08:59 PM


All times are GMT +1. The time now is 04:32 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"