Delete rows that are part of merged cells

Viewed 45

Good morning,

I hope someone can help me with this. I have the following excel table:

enter image description here

I would like to delete all the lines where "HFO", for example, is written (rows 16-18 in this case).

Is there any way to do it or to identify how many rows are part of a merged cell?

I have seen the topic below, but I it doesn't work for me because rows 10-15 have also merged cells and I don't want to delete them.

Delete rows with merged cells

Thank you!

1 Answers

MergeArea returns a Range object referenced to all merged cells. Because you need to delete the rows, then add EntireRow object:

enter image description here

Dim rng As Range

For Each rng In Range("C16:C24")
    If rng.Value = "HFO" Then rng.MergeArea.EntireRow.Delete
Next rng

Output after code:

enter image description here

Notice we deleted only those rows with merged cells and value "HFO"

Related