在公式中使用Union Command创建的范围

时间:2017-11-21 12:39:01

标签: vba excel-vba excel

我有一个使用Union命令创建的范围。我希望此联盟创建的范围在一个公式中,我将该范围内的所有值相加。我尝试过的所有内容都会出现错误。

我的范围创建方式的代码。

With ThisWorkbook.Worksheets("Sheet1")
    lastrow = .Cells(.Rows.Count, "N").End(xlUp).Row
    Application.ScreenUpdating = False
    For Each xRg In .Range("N1:N" & lastrow)
        If UCase(xRg.Text) = 1 Then
            If yRg Is Nothing Then
                Set yRg = .Range("C" & xRg.Row).Resize(, 1)
            Else
                Set yRg = Union(yRg, .Range("C" & xRg.Row).Resize(, 1))
            End If
        End If
    Next xRg
    Application.ScreenUpdating = True
End With

If Not yRg Is Nothing Then yRg.Select

我现在想要在总和中使用yRg

0 个答案:

没有答案
相关问题