Excel范围减法,可以忽略某些单元格中的错误?

时间:2015-08-27 00:21:16

标签: excel vba excel-vba range subtraction

我无法确定如何相互减去两个范围,H:H范围内的某些单元格具有“#N / A”,而范围D:D则没有错误。我知道在Excel中它是一个简单的“= H2-D2”并向下拖动但我正在录制宏并且想要自动化减法。到目前为止,这就是我所拥有的:

Dim quantity1, quantity2, rIntersect, Qdiff, x  As Range

Set quantity1 = Range("D:D")
Set quantity2 = Range("H:H")

Set rIntersect = Intersect(quantity1, quantity2)

For Each x In quantity1
If Intersect(rIntersect, x) Is Nothing Then
    If Qdiff Is Nothing Then
        Set Qdiff = x
    Else
        Set Qdiff = Application.Union(Qdiff, x)
    End If
End If
Next x

Range("J2").Select
Dim lastRowJ As Long
lastRowJ = Range("A" & Rows.Count).End(xlUp).Row
Range("J2").AutoFill Destination:=Range("J2:J" & lastRowJ)

0 个答案:

没有答案