0

为什么这会将数据复制到下一个空白单元格直到下一个完整单元格,然后获取该单元格的数据并重新开始?

Option Explicit

Sub CopyDown()

    Dim wsPOD As Worksheet
    Dim lastrow

    Set wsPOD = Sheets("PO Data")

With wsPOD
    lastrow = wsPOD.Range("F" & Rows.Count).End(xlUp).Row
            wsPOD.Range("A2:D" & lastrow).Select
            Selection.SpecialCells(xlCellTypeBlanks).Select
            Selection.FormulaR1C1 = "=R[-1]C"
    End With
End Sub

我了解大部分脚本,但我不了解这部分:

        Selection.SpecialCells(xlCellTypeBlanks).Select
        Selection.FormulaR1C1 = "=R[-1]C"

最后一部分对我来说尤其是胡言乱语,有人可以帮我理解吗?

4

1 回答 1

2

根据我的评论,您可以使用

选项显式

Sub CopyDown()

    Dim wsPOD As Worksheet
    Dim lastrow as long
    Dim EmptyCells as range

    Set wsPOD = Sheets("PO Data")

With wsPOD
    lastrow = .Range("F" & .Rows.Count).End(xlUp).Row
            set EmptyCells = .Range("A2:D" & lastrow).SpecialCells(xlCellTypeBlanks)
            EmptyCells.FormulaR1C1 = "=R[-1]C"
    End With
End Sub
于 2012-09-20T17:59:22.017 回答