excel的vba操作我要把每个选中的单元格内容汇合在一起。看我的代码

Dim str As String
Dim temp As String
For i = 1 To Selection.Count
temp = Selection.Item(i)
Selection.Item(i) = ""
str = str & temp
Next
Selection.Item(1) = str
如果区域是框选的,可以通过,如果区域是不连续的(按住ctrl点选)就不能汇合文本。求告知

试下这个:

Public Sub sss()

    Dim str As String, temp As String, CXrng As Range, XRrng As Range

    Set CXrng = Selection

    For Each XRrng In CXrng

        str = str & XRrng.Value

        XRrng.ClearContents

    Next

    CXrng(1) = str

End Sub

温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-11-11
Sub t()
temp = ""
For Each c In Selection
temp = temp & c
Next

Selection.Item(1) = temp
End Sub
相似回答