Sub test()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
'Assume your value is in Column C
For i = 1 To LR
n = Cells(i, 3).Value
If n > 1 Then
Cells(i, 3).EntireRow.Select
Selection.Copy
For j = 1 To n - 1
Cells(i + 1, 3).EntireRow.Insert
Next
End If
Next i
End Sub
That way your data file will be properly prepared and you will get the outcome you want
Sub MergeRepeatingRecords()
Dim r As Integer
Dim wdDoc As Document
Dim n As Integer
Dim iLastRecord As Integer
Set wdDoc = ActiveDocument
With wdDoc.MailMerge
'establish last record number
.DataSource.ActiveRecord = wdLastDataSourceRecord
iLastRecord = .DataSource.ActiveRecord
.Destination = wdSendToNewDocument
'step through Datasource records
r = 0
Do Until r = iLastRecord
.DataSource.LastRecord = r
.DataSource.FirstRecord = r
For n = 1 To .DataSource.DataFields("RepeatNumber").Value
.Execute
Next n
r = r + 1
Loop
End With
End Sub
DIM j as long, n as long
n = Cells(i, 3).Value
was empty at one point, so not an integer.Sub test2()
Dim LR As Long
Dim r As Long
Dim c As Integer
Dim n As Integer
Dim j As Integer
LR = Range("A" & Rows.Count).End(xlUp).Row
'Assume your value is in Column J (10)
c = 10
For r = LR To 2 Step -1
n = Cells(r, c).Value
For j = 1 To n - 1
Cells(r, c).EntireRow.Copy
Cells(r, c).EntireRow.Insert xlShiftDown
Next
Next r
End Sub
Title | # Comments | Views | Activity |
---|---|---|---|
Where should I install this function so it is available to my spreadsheets> | 4 | 38 | |
excel VBA sending mail | 9 | 41 | |
Convert .PDF | 6 | 43 | |
how can I correct in impaired MS Word 2013 invoice template print out? | 8 | 17 |
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
13 Experts available now in Live!