0
Private Sub CommandButton1_Click()
Dim rng As Range
Dim cell As Variant

Set rng = Range("C8:C12")

For Each cell In rng
    Sheets("Sheet1").Range("A1:H7").Copy Destination:=Sheets("Quantity").Range("XFD4").End(xlToLeft).Offset(-3, 3)
    Sheets("Quantity").Range("XFD1").End(xlToLeft).Offset(0, 1).Value = cell.Offset(1, -1).End(xlUp).Value
    Sheets("Quantity").Range("XFD2").End(xlToLeft).Offset(0, 1).Value = cell.Value
    Sheets("Quantity").Range("XFD3").End(xlToLeft).Offset(0, 1).Value = cell.Offset(0, 1).Value  
Next
End Sub

我想在这里完成的是skip blank cell/row. 因为它会将空数据复制到工作表中。是否有任何方法,例如 Not isEmpty 或 isBlank For loop?提前致谢。

4

1 回答 1

1

您应该能够检查IsEmpty(cell)单元格是否为空。

例如(未经测试):

For Each cell In rng
    If Not IsEmpty(cell) Then
        Sheets("Sheet1").Range("A1:H7").Copy Destination:=Sheets("Quantity").Range("XFD4").End(xlToLeft).Offset(-3, 3)
        Sheets("Quantity").Range("XFD1").End(xlToLeft).Offset(0, 1).Value = cell.Offset(1, -1).End(xlUp).Value
        Sheets("Quantity").Range("XFD2").End(xlToLeft).Offset(0, 1).Value = cell.Value
        Sheets("Quantity").Range("XFD3").End(xlToLeft).Offset(0, 1).Value = cell.Offset(0, 1).Value 
    End If 
Next
于 2013-01-01T18:52:39.503 回答