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.
CustomerData
Customer AA1##
A2##
A3##
Customer BB1##
Customer CC1##
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!
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,214,386
Messages
6,119,216
Members
448,876
Latest member
Solitario

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