Excel VBA to delete blank rows within a range

2019-09-09 06:14发布

I have worksheet that have data starting at A84, extending to column X. I use this VBA to select the entire range of data.

Dim Lastrow As Integer
Lastrow = Range("A:Z").Find("*", , , , xlByRows, xlPrevious).Row

Range("A84:X" & Lastrow).Select

Within that selected range, I need it to detect which rows are blank from columns A to Z and delete them. If there's data after column Z, the row should be deleted because I'm considering it blank.

1条回答
来,给爷笑一个
2楼-- · 2019-09-09 07:08

The comments sometimes adds characters. Here is the code:

Dim Lastrow As Integer
Lastrow = Range("A:Z").Find("*", , , , xlByRows, xlPrevious).Row


For i = Lastrow To 84 Step -1
    If Application.CountA(Range(Cells(i, 1), Cells(i, 26))) = 0 Then Rows(i).Delete
Next i
查看更多
登录 后发表回答