How to check what rows are grouped.

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

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!
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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