VBA: How to summarise and consolidate data into merged fields

abssorb

New Member
Joined
Apr 15, 2008
Messages
34
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
  5. 2011
  6. 2010
Platform
  1. Windows
Hi,

I have some data which has a one-to-many relationship tracking projects to companies, which serves well enough for information, however we now need to produce a 'pretty' report and they don't want to see duplicate lines. It's also necessary to fit corporate formatting (not shown) and be consistent week-to-week across many different users.

I'm not the best at VBA but I already have a macro that will take the data line-by-line, filter and preset in a pretty report, but it has duplicate rows as per the sample data. I need to find out how to merge cells which match criteria.
Does anyone have some examples or suggestions where to get started please?

Sample_excel.png
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Why not sort the data first by Company and Project ID and then run the macro.

You can sort it afterwards by Project ID and Company to revert it to how it was originally entered.

It is a good idea to have raw data in one worksheet and the analysis / reporting on another worksheet.
 
Upvote 0
It's just a faked sample. :) The actual data is non-disclosable. I've spotted an error in the mock-up, that ABC Widgets should not appear twice. Sorry about that.
The report is on a separate sheet, and the vba already sorts.

Determining which rows should result in merged cells, and then carrying out merge, is the bit I need help with please.
 
Upvote 0
If it helps anyone else, I found a solution here:



My example is working down through col D to a row number set as a variable.
VBA Code:
'  rr is set elsewhere as row number
Mergecells:
       
        For Each Rng In Range("D4:D" & rr)
            If Rng.Value = Rng.Offset(1, 0).Value And Rng.Value <> "" Then
                Range(Rng, Rng.Offset(1, 0)).Merge
                GoTo Mergecells
            End If
        Next
 
Upvote 0
I spoke to soon. the above only operates column by column.

I've spent all evening trying different code postings. I've made a better picture.


Merge_screenshot.png
 
Upvote 0

Forum statistics

Threads
1,214,990
Messages
6,122,626
Members
449,093
Latest member
catterz66

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