Repeat data N times on Word table from Excel

Arafat

Board Regular
Joined
May 3, 2011
Messages
61
Hi Folks, I am trying to repeat data on existing word table based on a cell value.
Example: i want to repeat Text "Hello" 10 times and "Bye" 6 times.

I have this code on in excel file, I am able to pass the data to the table but it wont repeat values as mentioned in cell value.Please let me know any modification to the existing code.THANK YOU.

Function FnFormatExistingTable()


Dim objWord


Dim objDoc


Dim objRange
Dim MyCell As Range, MyRange As Range
Dim sval As String
Set MyRange = Sheets("Sheet1").Range("A2")
Set MyRange = Range(MyRange, MyRange.End(xlDown))


Set objWord = CreateObject("Word.Application")


Set objDoc = objWord.Documents.Open("E:\BARCODE\Label 65.doc")


objWord.Visible = True
objDoc.Activate
Set objTable = objDoc.Tables(1)


Count = 0
'On Error Resume Next
Dim tbl As Table
Dim cl As Cell
For Each MyCell In MyRange
'If MyCell.Offset(0, 6).Value = "" Then
'GoTo fer
'End If
For Each tbl In objDoc.Tables
'MsgBox tbl.Cell
'For i = 1 To MyCell.Offset(0, 3).Value
For Each cl In tbl.Range.Cells
Count = Count + 1
If Count > MyCell.Offset(0, 6) Then
'GoTo fer
End If
If Len(cl.Range) = 2 Then
cl.Range.Text = MyCell.Offset(0, 5) & Chr(10) & MyCell.Offset(0, 1) & Chr(10) & MyCell.Offset(0, 4) & Chr(10) & "Rs." & MyCell.Offset(0, 2)
Else
Count = 0
End If
Next cl
'Next i
Next tbl
fer:
Count = 0
Next MyCell


MsgBox "Labels Created"


End Function
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Forum statistics

Threads
1,213,583
Messages
6,114,480
Members
448,574
Latest member
bestresearch

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top