Excel指定某区域字符串相加

我手里有一个表,从A1到A100都联系人邮箱,我想把这些联系人邮箱地址通过“,”加起来,然后就能用邮件系统发送邮件了,但是Excel竟然没有这个函数,只有通过VBA实现功能了。

Sub test()
    Dim str$, rng As Range
    str = ""
    For Each rng In [a1].CurrentRegion
        str = str & "," & rng
    Next
    [D1] = Right(str, Len(str) - 1)
End Sub

运行这个VBA,就能在D1这一个单元格中显示从A1到A100的所有邮件地址合并了。

发现CurrentRegion是好玩的属性,能返回所有连接的区域内所有单元格的属性:

http://www.excelperfect.com/index.php/2009/07/23/usecurrentregionproperty/

Leave a Reply

Your email address will not be published. Required fields are marked *