Hello,
I have an example below, I'd like to take the first row, copy it "n" number of times, then take the next row copy it the same "n" number of times, till the end of the rows.
Sample
ColA ColB ColC
TextA TextA1 TextA2
TextB TextB1 TextB2
TextC TextC1 TextC2
Results (for example 3 times)
ColA ColB ColC
TextA TextA1 TextA2
TextA TextA1 TextA2
TextA TextA1 TextA2
TextB TextB1 TextB2
TextB TextB1 TextB2
TextB TextB1 TextB2
TextC TextC1 TextC2
TextC TextC1 TextC2
TextC TextC1 TextC2
Configuration: Windows XP Internet Explorer 8.0
Try this macro
Sub test()
Dim n As Integer, rng As Range
n = InputBox("type the value of n")
Set rng = Range("a1")
rng.Select
line2:
Range(rng.Offset(1, 0), rng.Offset(3, 0)).EntireRow.Insert
Range(rng, rng.End(xlToRight)).Copy
Range(rng, rng.Offset(n, 0)).PasteSpecial
Set rng = rng.Offset(n + 1, 0)
If rng = "" Then
GoTo line1
Else
GoTo line2
End If
line1:
Application.CutCopyMode = False
Range("a1").Select
MsgBox "macro over"
End Sub
|
It works in my case. do an experiment open a new workbook.
|
Reply to venkat1926
|
Try this
Sub test()
Dim n As Integer, rng As Range
'n = InputBox("type the value of n")
Set rng = Range("a1")
rng.Select
line2:
n = InputBox("type no. of times you want to be repeated minus 1 for e.g if you wnat to be repeated 3 times type 2")
Range(rng.Offset(1, 0), rng.Offset(n, 0)).EntireRow.Insert
Range(rng, rng.End(xlToRight)).Copy
Range(rng, rng.Offset(n, 0)).PasteSpecial
Set rng = rng.Offset(n + 1, 0)
If rng = "" Then
GoTo line1
Else
GoTo line2
End If
line1:
Application.CutCopyMode = False
Range("a1").Select
MsgBox "macro over"
End Sub
|
I have a problem that might be similar to the history in this forum entry.
|
Netscyr
Sub test()
Dim rng As Range, c As Range
Dim rng1 As Range, c1 As Range
Dim dest As Range, j As Integer, k As Integer
Worksheets("sheet2").Cells.Clear
With Worksheets("sheet1")
Set rng = Range(.Range("A2"), .Range("A2").End(xlDown))
j = WorksheetFunction.CountA(.Rows("1:1"))
'msgbox j
For Each c In rng
Set rng1 = Range(c.Offset(0, 1), .Cells(c.Row, Columns.Count).End(xlToLeft))
'msgbox rng1.Address
For Each c1 In rng1
Set dest = Worksheets("sheet2").Cells(Rows.Count, "a").End(xlUp).Offset(1, 0)
'msgbox dest.Address
If c1 = "" Then GoTo line1
dest.Offset(0, 0) = c
dest.Offset(0, 1) = .Cells(1, c1.Column)
'dest.Offset(0, 2) = c1
line1:
Next c1
Next c
End With
End Sub
another method -pivot table of database.- ref: wlakenbach blog http://spreadsheetpage.com/... |
Aces... with minor tweaking for my 'real' document, it WORKS great, and I understand 50% of how it works :)
|
I apologize, I miss typed in my sample/request above....
|
It is a bother to modify a already created macro even it it is one's own.
Sub test()
Dim rng As Range, c As Range
Dim rng1 As Range, c1 As Range
Dim dest As Range, j As Integer, k As Integer
Worksheets("sheet2").Cells.Clear
With Worksheets("sheet1")
Set rng = Range(.Range("A2"), .Range("A2").End(xlDown))
j = WorksheetFunction.CountA(.Rows("1:1"))
'msgbox j
For Each c In rng
Set rng1 = Range(c.Offset(0, 1), .Cells(c.Row, Columns.Count).End(xlToLeft))
'msgbox rng1.Address
For Each c1 In rng1
Set dest = Worksheets("sheet2").Cells(Rows.Count, "a").End(xlUp).Offset(1, 0)
'msgbox dest.Address
If c1 = "" Then GoTo line1
'dest.Offset(0, 0) = c
'dest.Offset(0, 1) = .Cells(1, c1.Column)
'dest.Offset(0, 2) = c1
dest = c
dest.Offset(0, 1) = c1
dest.Offset(0, 2) = .Cells(1, c1.Column)
line1:
Next c1
Next c
End With
With Worksheets("sheet2").Columns("c:c")
.NumberFormat = "dd-mmm-yy"
End With
End Sub
|
Reply to venkat1926
|
I have added two more rows to check my macro. This is in SHEET1 as follows
Sub test()
Dim j As Integer, k As Integer, m As Integer, n As Integer
j = Range("a1").End(xlDown).Row
'j is hte lsst row
k = j
Do
If k = 1 Then Exit Do
m = Cells(k, "b") - Cells(k, "A")
'MsgBox m
'Range(Cells(k + 1, "A"), Cells(k + m, "A")).Select
Range(Cells(k + 1, "A"), Cells(k + m, "A")).EntireRow.Insert
For n = 1 To m
Cells(k, 1).EntireRow.Copy Cells(k + n, 1)
Next n
For n = 1 To m
Cells(k + n, 1) = Cells(k, 1) + n
Next n
k = k - 1
'MsgBox k
Loop
End Sub
Sub undo()
Worksheets("sheet1").Cells.Clear
Worksheets("sheet2").UsedRange.Copy Worksheets("sheet1").Range("A1")
End Sub any bug post back. if ok confirm |
I'm trying to do something very similar but MUCH simpler I think.
ColA ColB ColC
A1 text 5 A1 text
A1 text
A1 text
A1 text
A1 text
Then you leave Col C alone and clear out A and B. Put in new input to get the following for example: ColA ColB ColC A1new 7 A1 text A1 text A1 text A1 text A1 text A1new A1new A1new A1new A1new A1new A1new </code> You can keep using it to create one big long column of entries. I'd gladly send someone some $$ via paypal for the help if it's done in the next few hours. |