Merging Cells Based On Equal Value WIthin A Dynamic Range

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am looking for some help with a VBA based process.

I have a worksheet in which there are several groups of different data. The groups are defined by their sorted values in column R. Their are groups of "D", "F", "C" etc. with each group holdinf a dynamic number of rows (if any). The groups are separated by blank rows.

What I need to do is assess the values in column B of only the "D" section, and merge those cells in column B, that have equal values.

For example ... starting data:
WS 29-May-23.xlsx
ABCDEFGHIJKLMNOPQR
2data<7:30PdatadatadatadatadatadatadatadatadatadatadatadatadatadatadataD
3data<7:30PdatadatadatadatadatadatadatadatadatadatadatadatadatadatadataD
4data<7:30PdatadatadatadatadatadatadatadatadatadatadatadatadatadatadataD
5data<8:00PdatadatadatadatadatadatadatadatadatadatadatadatadatadatadataD
6data<9:15PdatadatadatadatadatadatadatadatadatadatadatadatadatadatadataD
7data<9:15PdatadatadatadatadatadatadatadatadatadatadatadatadatadatadataD
8data<10:00PdatadatadatadatadatadatadatadatadatadatadatadatadatadatadataD
9data<10:00PdatadatadatadatadatadatadatadatadatadatadatadatadatadatadataD
10data<10:00PdatadatadatadatadatadatadatadatadatadatadatadatadatadatadataD
11data<11:00PdatadatadatadatadatadatadatadatadatadatadatadatadatadatadataD
12
13datadatadatadatadatadatadatadatadatadatadatadatadatadatadatadataF
14datadatadatadatadatadatadatadatadatadatadatadatadatadatadatadataF
15datadatadatadatadatadatadatadatadatadatadatadatadatadatadatadataF
16
17datadatadatadatadatadatadatadatadatadatadatadatadatadatadatadataC
18datadatadatadatadatadatadatadatadatadatadatadatadatadatadatadataC
19datadatadatadatadatadatadatadatadatadatadatadatadatadatadatadataC
Sheet20


Would result in:
WS 29-May-23.xlsx
ABCDEFGHIJKLMNOPQR
2data<7:30PdatadatadatadatadatadatadatadatadatadatadatadatadatadatadataD
3datadatadatadatadatadatadatadatadatadatadatadatadatadatadatadataD
4datadatadatadatadatadatadatadatadatadatadatadatadatadatadatadataD
5data<8:00PdatadatadatadatadatadatadatadatadatadatadatadatadatadatadataD
6data<9:15PdatadatadatadatadatadatadatadatadatadatadatadatadatadatadataD
7datadatadatadatadatadatadatadatadatadatadatadatadatadatadatadataD
8data<10:00PdatadatadatadatadatadatadatadatadatadatadatadatadatadatadataD
9datadatadatadatadatadatadatadatadatadatadatadatadatadatadatadataD
10datadatadatadatadatadatadatadatadatadatadatadatadatadatadatadataD
11data<11:00PdatadatadatadatadatadatadatadatadatadatadatadatadatadatadataD
12
13datadatadatadatadatadatadatadatadatadatadatadatadatadatadatadataF
14datadatadatadatadatadatadatadatadatadatadatadatadatadatadatadataF
15datadatadatadatadatadatadatadatadatadatadatadatadatadatadatadataF
16
17datadatadatadatadatadatadatadatadatadatadatadatadatadatadatadataC
18datadatadatadatadatadatadatadatadatadatadatadatadatadatadatadataC
19datadatadatadatadatadatadatadatadatadatadatadatadatadatadatadataC
Sheet20
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hi Ark, it's a pleasure to respond to your threads again

Try this:

VBA Code:
Sub Merging_Cells()
  Dim i&, f As Range
  Application.ScreenUpdating = False
  Application.DisplayAlerts = False
  Range("B:B").HorizontalAlignment = xlCenter
  Range("B:B").VerticalAlignment = xlCenter
  For i = 2 To Range("B" & Rows.Count).End(3).Row
    Set f = Range("B:B").Find(Range("B" & i).Value, , xlValues, xlWhole, xlByRows, xlPrevious, False)
    If f.Row > i Then
      Range(Range("B" & i), f).Merge
      i = f.Row
    End If
  Next
  Application.ScreenUpdating = True
  Application.DisplayAlerts = True
End Sub

--------------
Let me know the result and I'll get back to you as soon as I can.
Cordially
Dante Amor
--------------​
 
Upvote 0

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

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