Merge Cells Automatically using VBA

Sefty

Board Regular
Joined
Apr 5, 2022
Messages
68
Office Version
  1. 365
Platform
  1. Windows
Hello

I'm looking for something to automatically merge text of the text in a cell. This can either be immediately or by using VBA and running a macro to do all of them at once. Example for data merge data football, and I'm looking to merge by using VBA to data volly, basketball, and tenis.
Thanks....
1658283471276.png
 
Thanks.

Please remember XL2BB for sample data. ;)

Try this

VBA Code:
Sub MergeSports_v3()
  Dim rA As Range
 
  With Range("A2", Range("A" & Rows.Count).End(xlUp))
    .Value = Evaluate(Replace(Replace("if(#=%,"""",#)", "#", .Address), "%", .Offset(-1).Address))
    For Each rA In Range(.Address).SpecialCells(xlBlanks).Areas
      rA.Offset(-1).Resize(rA.Rows.Count + 1).MergeCells = True
    Next rA
  End With
End Sub
Wow code successful, thank you very much 😁
The following is followed by the data, the code has been successful with the data as below 😄

Matrix Pembangunan v29072022_17 (Recovered).xlsx
AB
1Before After
2FootballFootball
3Football
4Football
5Football
6Football
7SwimmingSwimming
8Swimming
9Swimming
10Swimming
11Swimming
12Swimming
13RunRun
14Run
15Run
16BadmintonBadminton
17Badminton
18Badminton
19Badminton
Sheet2
 
Upvote 0

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,223,630
Messages
6,173,454
Members
452,514
Latest member
cjkelly15

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