Formatting of data on a Summary sheet

Muzza77

New Member
Joined
Jul 19, 2016
Messages
2
Hi,

I am having trouble with formatting of data on a summary sheet as I need to loop through a couple of loops to collect the data, this is where my issue is I think.

I have a worksheet for each customer and this worksheet can contain the details for multiple sites - each site in a new column.

I am trying to loop through each worksheet (I have this working for only one site as the cell references are static), my trouble starts when I need to loop through each site on the worksheet before moving to the next worksheet.

Below is a sample of the data on a worksheet. All worksheets have the same format as they are generated from a template.

Excel 2013 64 bit
ABCD
1Customer NameCustomer A
2
3Site DetailsSite 1Site 2
4Address
5Town
6StateVICNSW
7Postcode
8Contact Name
9Contact Phone
10Software
11Version7.50.4997.40.746
12Serial Number
13SMAYesNo
14Aniversary Date30/04/2017

<colgroup><col style="width: 25pxpx"><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Customer 1



This is what the master worksheet looks like after running the update.

Excel 2013 64 bit
ABCDEFG
4CustomerSMASMA Aniversary DateVersion
5Customer 1 Site 1Yes30/04/20177.50.499Yes30/04/20177.50.499
6ABC Site 1Yes1/06/20177.40.756Yes1/06/20177.40.756
7No SMA Site 1No0/01/19007.40.756No0/01/19007.40.756

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Master



On the master worksheet I'd like the Customer column to contain a list of the "Customer + Site" and the detail for each of these on the same row in the corresponding columns.

My current (and as yet incomplete) code is below:

Code:
Private Sub UpdateSummary_Click()


Dim wsMASTER As Worksheet, Sh As Worksheet
Dim Basebook As Workbook
Dim myCell As Range
Dim SiteRange As Range
Dim ColNum As Integer
Dim RwNum As Long


Set wsMASTER = ThisWorkbook.Worksheets("Master")
    wsMASTER.Rows("5:" & wsMASTER.Rows.Count).Clear


Set Basebook = ThisWorkbook
RwNum = 4


    For Each Sh In Basebook.Worksheets
        If Sh.Name <> wsMASTER.Name And Sh.Visible Then
            ColNum = 1
            RwNum = RwNum + 1
            
            Set SiteRange = Sh.Range("C3:C10")
            For Each Cell In SiteRange
                SiteCol = 3
                SiteRow = 3
                If Cell.Value <> "" Then
                    wsMASTER.Cells(RwNum, 1).Value = Sh.Name & " " & Sh.Cells(SiteRow, SiteCol).Value
                    
                    For Each myCell In Sh.Range("C13:C14,C11")
                        ColNum = ColNum + 1
                        wsMASTER.Cells(RwNum, ColNum).Formula = _
                        "='" & Sh.Name & "'!" & myCell.Address(False, False)
                    Next myCell
                End If
            Next Cell
        End If
    Next Sh


MsgBox "Master Sheet Updated."
End Sub

I'm pretty sure the issue is somewhere in the cell references and where to increment counters etc. Just not sure how to go about it in code.

Regards,

Muzza.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Does this do what you're after

Code:
Private Sub UpdateSummary_Click()
    Dim wsMASTER As Worksheet, Sh As Worksheet
    Dim Basebook As Workbook
    Dim SiteRange As Range
    Dim RwNum As Long
    Dim lCol As Long
    Dim cCol As Long
    
    Set wsMASTER = ThisWorkbook.Worksheets("Master")
    wsMASTER.Rows("5:" & wsMASTER.Rows.Count).Clear
    Set Basebook = ThisWorkbook
    RwNum = 5
    For Each Sh In Basebook.Worksheets
        lCol = Sh.Cells(3, Sh.Columns.Count).End(xlToLeft).Column
        If Sh.Name <> wsMASTER.Name And Sh.Visible Then
            Set SiteRange = Sh.Range(Sh.Cells(3, 3), Sh.Cells(3, lCol))
            For Each Cell In SiteRange
                cCol = Cell.Column
                wsMASTER.Cells(RwNum, 1).Value = Sh.Name & " " & Sh.Cells(3, cCol).Value
                wsMASTER.Cells(RwNum, 2).Value = Sh.Cells(13, cCol).Value
                wsMASTER.Cells(RwNum, 3).Value = Sh.Cells(14, cCol).Value
                wsMASTER.Cells(RwNum, 4).Value = Sh.Cells(11, cCol).Value
                RwNum = RwNum + 1
            Next Cell
        End If
    Next Sh
    MsgBox "Master Sheet Updated."
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,926
Messages
6,122,305
Members
449,079
Latest member
juggernaut24

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