加入功能不适用于水平范围?

时间:2015-07-01 18:22:59

标签: excel vba delimiter

我想将一个范围转换为带有Join函数的自定义分隔符的字符串,而这适用于垂直范围我无法为水平范围执行此操作。这适用于柱/垂直范围:

Join(Application.Transpose(Workbooks("Book3").Sheets(1).Range("A1:A5").value), ";")

现在,当我尝试使用水平范围时,我会收到错误“无效的过程调用或参数”

Join(Application.Transpose(Workbooks("Book3").Sheets(1).Range("A1:D1").value), ";")
Join(Workbooks("Book3").Sheets(1).Range("A1:D1").value, ";")

如何做到这一点?

2 个答案:

答案 0 :(得分:1)

Join(Application.Transpose(Application.Transpose( _
      Workbooks("Book3").Sheets(1).Range("A1:D1").value)), ";")

答案 1 :(得分:1)

只要不对可以转置的单元格数量进行限制,就可以尝试这样的函数:

Function JoinRange(rg As Range, Optional Delim As String = " ")
Dim V As Variant

V = rg
If UBound(V, 1) = 1 Then 'One Row
    JoinRange = Join(WorksheetFunction.Index(V, 1, 0), Delim)
Else
    JoinRange = Join(WorksheetFunction.Transpose(V), Delim)
End If
End Function