Excel中是否有方法获取列并将其转换为串联字符串

Excel中是否有方法获取列并将其转换为串联字符串,excel,concatenation,Excel,Concatenation,我想将多行中的名称列表合并到一个单元格中,如下所示: 乔 鲍勃 乔治 并将其转换为一个具有以下内容的单元格: “Joe”、“Bob”、“George”如果他们不想做你想做的事,可能会有所帮助。这很简单。您可能希望与trim、left、right和find结合使用。享受吧 我知道有两种基本方法 最快的方法- A列列出了你的名字 将A1的值复制到B1-“Joe” 在B2中,输入公式`=B1&“,”&A2` 选择B2,复制公式,然后将B列的其余部分粘贴到A列的整个长度。B列的最后一个单元格将包含A列中

我想将多行中的名称列表合并到一个单元格中,如下所示:


鲍勃
乔治

并将其转换为一个具有以下内容的单元格:


“Joe”、“Bob”、“George”

如果他们不想做你想做的事,可能会有所帮助。

这很简单。您可能希望与trim、left、right和find结合使用。享受吧


我知道有两种基本方法

最快的方法-

  • A列列出了你的名字
  • 将A1的值复制到B1-“Joe”
  • 在B2中,输入公式`=B1&“,”&A2`
  • 选择B2,复制公式,然后将B列的其余部分粘贴到A列的整个长度。B列的最后一个单元格将包含A列中以逗号分隔的值列表。 更好的方法-
    制作自己的vb函数,在一系列单元格中进行迭代,而不是像
    sum
    那样对它们求和,只需将它们串联起来即可


    我一直都在这样做,所以如果有人知道MS文档中某个地方隐藏了一个连接范围的实际内置Excel函数,你就可以节省时间了。

    你可以将GetString与ADO记录集一起使用

    Dim cn As Object
    Dim rs As Object
    Dim strFile As String
    Dim strCon As String
    Dim strSQL As String
    Dim s As String
    
    ''This is not the best way to refer to the workbook
    ''you want, but it is very conveient for notes
    ''It is probably best to use the name of the workbook.
    
    strFile = ActiveWorkbook.FullName
    
    strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFile _
        & ";Extended Properties=""Excel 8.0;HDR=No;IMEX=1"";"
    
    Set cn = CreateObject("ADODB.Connection")
    Set rs = CreateObject("ADODB.Recordset")
    
    cn.Open strCon
    
    strSQL = "SELECT * " _
           & "FROM [Sheet1$A:A] "
    
    rs.Open strSQL, cn, 3, 3
    
    ''http://www.w3schools.com/ado/ado_getstring.asp
    ''str = rs.GetString(format,rows,coldel,rowdel,nullexpr)
    s = rs.GetString(, , , ", ")
    ActiveSheet.Range("B1") = s
    
    ''Tidy up
    rs.Close
    Set rs = Nothing
    cn.Close
    Set cn = Nothing
    

    尝试使用转置功能并按F9键:

    +---+--------+
    |   |   A    |
    +---+--------+
    | 1 | Joe    |
    | 2 | Bob    |
    | 3 | George |
    +---+--------+
    
    B1:(输入功能栏)

    突出显示转置(A1:A3),然后按F9

    它将为您提供:

    {"Joe","Bob","George"}
    
    复制并粘贴该列表。就这样

    要连接单词,只需执行以下操作:

    =CONCATENATE(TRANSPOSE(A1:A3))
    
    突出显示转置(A1:A3),按F9,然后卸下括号:

    =CONCATENATE("Joe","Bob","George")
    

    将其作为宏添加到Excel工作表中,并将其作为输入范围和分隔符的自定义函数使用

    Function Concat(myRange As Range, Optional myDelimiter As String) As String
      Dim r As Range
      Application.Volatile
      For Each r In myRange
        If Len(r.Text) Then
          Concat = Concat & IIf(Concat <> "", myDelimiter, "") & r.Text
        End If
      Next
    End Function
    
    函数Concat(myRange作为范围,可选myDelimiter作为字符串)作为字符串
    调光范围
    应用程序。挥发性
    对于myRange中的每个r
    如果Len(右文本)那么
    Concat=Concat&IIf(Concat“”,myDelimiter“”)和r.Text
    如果结束
    下一个
    端函数
    
    用一个问题回答了这个问题。如果链接死了,这个答案几乎没有用处
    Function Concat(myRange As Range, Optional myDelimiter As String) As String
      Dim r As Range
      Application.Volatile
      For Each r In myRange
        If Len(r.Text) Then
          Concat = Concat & IIf(Concat <> "", myDelimiter, "") & r.Text
        End If
      Next
    End Function