将单元格存储在范围内,然后在1中删除

时间:2014-01-09 11:38:53

标签: excel-vba vba excel

我创建了以下代码,它的目的是删除数据之间存在的R列中的空单元格,问题是如何在范围内存储空白单元格,有什么建议吗?

Sub Macro1()

Dim lastRow_1 As Long
Dim counter_1 As Long
Dim rng_1 As Range, aCell As Range

lastRow_1 = Range("R" & Rows.Count).End(xlUp).Row

MsgBox lastRow_1

counter_1 = 1

For counter_1 = 1 To lastRow_1

    If Trim(Range("R" & counter_1).Value) = "" Then

       Set aCell = Range("R" & counter_1)

       rng_1 = Union(rng_1, aCell)

    End If

Next


    rng_1.Delete xlUp
End Sub

1 个答案:

答案 0 :(得分:1)

假设R200是范围内的最后一个单元格

range("R1:R200").SpecialCells(xlCellTypeBlanks).Delete