Macro to delete blank rows In specific range

yeo_1987

New Member
Joined
May 17, 2019
Messages
4
Hi pals. My spreadsheet has some blank cells in B7:B51. Although they’re blank but they actually contain formula (I turn = 0 to blank).

I understand that there are some ways to delete the rows manually but I need a macro to done it automatically.

Can you guys help me to write the macro with these criteria? Thanks in advanced
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Try

Code:
Sub MM1()
  With Range("B7:B51")
    .Replace "", "#N/A", xlWhole, , False, , False, False
    Columns("B").SpecialCells(xlConstants, xlErrors).EntireRow.Delete
  End With
End Sub
 
Upvote 0
Try

Code:
Sub MM1()
  With Range("B7:B51")
    .Replace "", "#N/A", xlWhole, , False, , False, False
    Columns("B").SpecialCells(xlConstants, xlErrors).EntireRow.Delete
  End With
End Sub


Hi, Michael. First of all thanks for you reply & help.

I ran the macro but ended with run-time error "1004", no cell were found.

I was thinking isn't something to do with my merged column as I merged column B to H into B.
 
Upvote 0
I don't have Excel at the moment, but that would cause problems !
Instead of merging cells, try centering them.......
Highlight the cells>>formta cells>>alignment tab>>Horizontaldropdown>>"center across selection"
Then retry the code.

Merging cells and working with VBA will break your heart !!!
 
Upvote 0
I don't have Excel at the moment, but that would cause problems !
Instead of merging cells, try centering them.......
Highlight the cells>>formta cells>>alignment tab>>Horizontaldropdown>>"center across selection"
Then retry the code.

Merging cells and working with VBA will break your heart !!!


Hi, Michael. Thanks again for your reply. I have unmerged the column and re-ran your VBA. Still get error but I found that it works if I delete the formula in column B. In my case the formula in column B is [ =IF(DataSheet!B28=0,"",DataSheet!B28) ]

Kindly advise how to delete the blank rows even they contain formula. Thanks
 
Upvote 0
OK, try this method then

Code:
Sub MM2()
Dim i As Long
    For i = 51 To 7 Step -1
        If Range("B" & i).Value = "" Then Rows(i).Delete
    Next i
End Sub
 
Upvote 0
Although theyÂ’re blank but they actually contain formula
Try

Code:
Sub MM1()
  With Range("B7:B51")
    .Replace "", "#N/A", xlWhole, , False, , False, False
    Columns("B").SpecialCells([B][COLOR="#FF0000"]xlConstants[/COLOR][/B], xlErrors).EntireRow.Delete
  End With
End Sub
Michael... please note what I highlighted in red.
 
Upvote 0
Gotcha....thanks Rick..
From post #5

Code:
=IF(DataSheet!B28=0,"",DataSheet!B28)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,248
Members
452,623
Latest member
cliftonhandyman

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