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.
<tbody>
</tbody>
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.
Customer | Data |
Customer A | A1## |
A2## | |
A3## | |
Customer B | B1## |
Customer C | C1## |
C2## |
<tbody>
</tbody>
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!