VBAMilennial
New Member
- Joined
- Aug 7, 2019
- Messages
- 1
My question is, how do I find which consecutive rows are grouped then store those rows and use them for other columns.
I'm trying to create a macro that allows me to take data from an excel sheet and place it in bookmarks of a word document. Below is the code I already have
However, I'm drawing a blank where different customers have different numbers of parts and etc. The table below gives an example.
[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD]Customer[/TD]
[TD]Data[/TD]
[/TR]
[TR]
[TD]Customer A[/TD]
[TD]A1##[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]A2##[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]A3##[/TD]
[/TR]
[TR]
[TD]Customer B[/TD]
[TD]B1##[/TD]
[/TR]
[TR]
[TD]Customer C[/TD]
[TD]C1##[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]C2##[/TD]
[/TR]
</tbody>[/TABLE]
Ex. How do I find that Customer A is grouped to rows 2 through 4, then take the data in column B - rows 2 through 4 - and apply it to the word doc?
Many Thanks!
I'm trying to create a macro that allows me to take data from an excel sheet and place it in bookmarks of a word document. Below is the code I already have
Code:
Sub DocGenerator()
Dim WordApp As Word.Application
Dim WordDoc As Word.Document
Dim r As Long
Dim FileName As String
Set WordApp = GetObject(, "Word.Application")
FileName = ThisWorkbook.Path & "\Letter_"
r = 2
Do Until IsEmpty(Cells(r, 1))
Set WordDoc = WordApp.Documents.Open(ThisWorkbook.Path & "\Letter_Word.docx")
WordDoc.Bookmarks("CustomerName").Range.InsertAfter Cells(r, 1).Text
WordDoc.Bookmarks("Data").Range.InsertAfter Cells(r, 2).Text
WordDoc.SaveAs2 FileName & Cells(r, 1).Text
WordDoc.Close
r = r + 1
Loop
End Sub
However, I'm drawing a blank where different customers have different numbers of parts and etc. The table below gives an example.
[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD]Customer[/TD]
[TD]Data[/TD]
[/TR]
[TR]
[TD]Customer A[/TD]
[TD]A1##[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]A2##[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]A3##[/TD]
[/TR]
[TR]
[TD]Customer B[/TD]
[TD]B1##[/TD]
[/TR]
[TR]
[TD]Customer C[/TD]
[TD]C1##[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]C2##[/TD]
[/TR]
</tbody>[/TABLE]
Ex. How do I find that Customer A is grouped to rows 2 through 4, then take the data in column B - rows 2 through 4 - and apply it to the word doc?
Many Thanks!