Delete a row in Excel VBA

baron33

New Member
Joined
May 16, 2018
Messages
3
The condition is that in Column A, if the cell (A1,A2,A3....) is a merged cell, then delete the entire row and the row above this cell
I know how to delete one entire row but I duplicate the language when trying to delete the 2nd row (can I put them together?)




Sub test()
Dim i As Integer
For i = 1 To 300 Step 1
If Cells(i, 1).MergeCells = True Then Rows(i - 1).EntireRow.Delete 'delete the row above the merged cell
End If
Next i

For i = 1 To 300 Step 1
If Cells(i, 1).MergeCells = True Then Rows(i).EntireRow.Delete 'delete another row where the merged cell is
End If
Next i

End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Maybe....

Code:
Sub test()
    Dim i As Long
    For i = 300 To 2 Step -1
        If Cells(i, 1).MergeCells = True Then Rows(i).Offset(-1).Resize(2).Delete    
    Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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