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
If you are experiencing a similar issue, please ask a related question
Title | # Comments | Views | Activity |
---|---|---|---|
Excel totals by filter - Automated | 4 | 36 | |
Embedded links don't work in converted PDF file | 8 | 66 | |
Mail merge IF Statements | 8 | 39 | |
Create Excel formula on dynamic data | 5 | 30 |
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
23 Experts available now in Live!