Use formula or VBA to merge cells

woah

New Member
Joined
May 10, 2023
Messages
24
Office Version
  1. 2016
Platform
  1. Windows
Hi there,

I got data like the picture. I want to merge cells of the raw data, but some contains dpulicate cells and blank cells. How can i use formula or VBA to have the desired outcome like the picture?

I got several sets of data. Some cells just contains values, but some cells contatin formula. Not sure whether it will affect the outcome.

Thank you all for your advice.

P.S. I have installed XL2BB, but nothing happened when I tried to paste it in the post. Not sure how to be able to use it.

1684658260779.png
 

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
Hi
Try
VBA Code:
Sub test()
Dim lr&, i&
lr = Cells(Rows.Count, 3).End(xlUp).Row
With Range("B3:B" & lr)
    .SpecialCells(4).FormulaR1C1 = "=R[-1]C"
    .Value = .Value
 Application.DisplayAlerts = False
    For i = lr To 3 Step -1
        If Cells(i, 2) = Cells(i + 1, 2) Then Range(Cells(i, 2), Cells(i + 1, 2)).Merge
    Next
 .HorizontalAlignment = xlCenter
 .VerticalAlignment = xlCenter
  End With
Application.DisplayAlerts = True
End Sub
 
Upvote 1
Solution
You are very welcome
And thank you for the feedback
Be happy and safe
 
Upvote 1

Forum statistics

Threads
1,223,907
Messages
6,175,301
Members
452,633
Latest member
DougMo

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