Find if Cells are grouped

AntMac

Board Regular
Joined
Dec 1, 2009
Messages
146
I am trying to write a macro that can go down a column and find if multiple rows in the column are grouped. If they are, then I would like for it to ungroup them then place the value in all of the rows that were grouped. In other words if A1 and A2 were grouped, ungroup them and then put the value that was in A1 into A2. Anyone can help with this?
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Actually I used the wrong word, which is why I'm having trouble finding the answer. I am trying to find if they are merged not grouped. I just want the value that's in the merged cell to be in all the cells that are merged. So, kind of undoing the merge if you will.
 
Upvote 0
OK, I understand what you want to do.
I'm sorry, I don't know how to code a solution for that.
Anyone else ?
 
Upvote 0
One word makes a huge difference. Now that I searched google on MERGED instead of grouped, I think I have found the main function that I need. That being ...MergeArea.Rows.Count This tells me how many rows are merged. Now just need some if thens around this and I should be at a solution. Thanks for your help! Even though you might feel you didn't, it did big time!!!
 
Upvote 0
Just in case someone was stomped like I was here's a sample code. I wasn't sure how to find the number to go to because the way I normally do that would be confused by grouped cells. So, I just put in the number I needed for this purpose.

Code:
Sub Remove_Grouping()


Application.ScreenUpdating = False
For i = 1 To 261
        'RowCount = Range("A" & i).MergeArea.Rows.Count
        RowCount = ActiveCell.MergeArea.Rows.Count
        If RowCount = 1 Then
        GoTo Here
        Else


'IsGrouped = ActiveCell.MergeCells
For c = 1 To RowCount - 1
store = ActiveCell.Value
ActiveCell.MergeArea.UnMerge
ActiveCell.Offset(1, 0).Select
ActiveCell.Value = store
i = i + 1
Next c


'MsgBox (RowCount)
End If
Here:
ActiveCell.Offset(1, 0).Select
Next i


Application.ScreenUpdating = True
MsgBox ("Done")


End Sub
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,194
Members
453,021
Latest member
pingpong7117

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