vba to help with merged cells

dshafique

Board Regular
Joined
Jun 19, 2017
Messages
171
Hey guys, I am trying to create a macro which deals with merged cells. The data I deal with comes from a table in powerpoint. when i copy the data over a lot of the cells end up being merged (I'm not sure why, but it's not merged in the ppt). what I want to do is to unmerge all the cells, then append any data that's in the blank lines in between. there are only 2 columns which have data that isnt merged.

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]John Smith[/TD]
[TD]Data[/TD]
[TD]Data[/TD]
[TD]Data[/TD]
[TD]Data[/TD]
[TD]Data[/TD]
[TD]Data[/TD]
[TD]email Data[/TD]
[TD]app data[/TD]
[TD]data[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]email data[/TD]
[TD]app data[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]email data[/TD]
[TD]app data[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]john smith[/TD]
[TD]data [/TD]
[TD]data[/TD]
[TD]data[/TD]
[TD]data[/TD]
[TD]data[/TD]
[TD]data[/TD]
[TD]email data[/TD]
[TD]app data[/TD]
[TD]data[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]app data[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

roughly how the table looks after unmerging


basically pseudo code:

1.) select everything
2.) unmerge cells
3.) check name cell to see if it's empty
if empty check if email data column is empty
if email data column is NOT empty, append data to email data cell above
else check app data cell and if NOT empty, append to the cell above.
4.) delete the whole row after

if anyone could give any guidelines that would be greatly appreciated. thanks
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
How about
Code:
Sub UnMergeCombine()
   Dim Rng As Range
   
   ActiveSheet.UsedRange.MergeCells = False
   For Each Rng In Range("G:G").SpecialCells(xlBlanks).Areas
      Rng.Offset(-1, 1).Resize(1, 1).Value = Join(Application.Transpose(Rng.Offset(-1, 1).Resize(Rng.Count + 1).Value), ", ")
      Rng.Offset(-1, 2).Resize(1, 1).Value = Join(Application.Transpose(Rng.Offset(-1, 2).Resize(Rng.Count + 1).Value), ", ")
   Next Rng
   Range("G:G").SpecialCells(xlBlanks).EntireRow.Delete
End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,249
Members
452,623
Latest member
Techenthusiast

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