我正在尝试获取包含两个组合范围的范围的Rows.Count:
Set rng = Union(Range1,Range2)
不幸的是,rng.Rows.Count返回Range1的Rows.Count,我希望它返回Range1 + Range2的Rows.Count。
我测试的实际范围是:$A$27:$G$41,$A$43:$G$43
它的Rows.Count属性返回15但在此范围内有16行。
任何想法如何在没有太多杂耍的情况下获得正确的Rows.Count?
答案 0 :(得分:2)
试试这个
Dim arr as range
Dim rws as long
For each arr in rng.areas
Rws = rws + arr.rows.count
Next
答案 1 :(得分:0)
试试这个:
Sub Test()
Dim rng As Range
Res = 0
Set rng1 = Range("A27:G41")
Set rng2 = Range("A43:G43")
Set rng = Union(rng1, rng2)
For Each area In rng.Areas
Res = Res + area.Rows.Count
Debug.Print Res
Next area
End Sub
希望这有帮助。