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.
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