构造包含单元格的“范围”多次 [英] Constructing a `Range` containing a cell multiple times

查看:109
本文介绍了构造包含单元格的“范围”多次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以轻松构建一个范围,其中同一个单元格出现两次(在这种情况下为单元格B1):

I can easily construct a Range in which the same cell appears twice (in this case cell B1):

Sub IAmTheCount()
    Dim r1 As Range, r2 As Range, r3 As Range
    Set r1 = Range("A1:B1")
    Set r2 = Range("B1:B2")
    Set r3 = Union(r1, r2)
    MsgBox r3.Count
End Sub

如何构建同一个单元格出现两次以上的范围?

How can I construct a range in which the same cell appears more than twice??

推荐答案

我不是确定如果我在你的头脑里面,不是这样,但这似乎是计数和包括单元格B1三次并作为一个明确的范围。

I'm not sure if I am inside your head or not with this, but this seems to count and include cell B1 three times and act as an explicit range.

Sub IAmTheCount()
    Dim r1 As Range, r2 As Range, r3 As Range, r4 As Range
    Set r1 = Range("A1:B1")
    Set r2 = Range("B1:B5")
    Set r3 = Range("B1:C2")
    Set r4 = Union(r1, r2, r3)
    MsgBox r4.Count & " - " & r4.Address
    r4.Interior.ColorIndex = 4
End Sub

这篇关于构造包含单元格的“范围”多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆