Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I delete all the MergeCells

Status
Not open for further replies.

yarondavid

Programmer
May 8, 2006
20
IL
Hi

I have some rows which are in MergeCells. I want to know how can I delete all the rows that are Merged

Thanks
 



Hi,

You actually want to DELETE rows having merged cell, not just 1) UNMERGE and 2) delete empty rows?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
I'm with Skip... Deleting rows containing merged cells will lead to the loss of any other data on that row. It would be safer to unmerge the merged cells, then delete the empty rows, leaving the un-empty rows in your data set for processing.

If you are absolutely certain that this will never be the case, then this code should give you a starting point.

Code:
Sub DeleteRowsContainingMergedCells()
    
    Dim Rw As Integer
    Dim Col As Integer
    
    For Rw = 10 To 1 Step -1  ' <-- Change the 10 to your actual number of rows
        For Col = 1 To 10     ' <-- Change the 10 to your actual number of columns
            If Cells(Rw, Col).MergeCells = True Then
                Rows(Rw).Delete
                Exit For
            End If
        Next Col
    Next Rw
    
End Sub

Glenn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top