我在Excel中有几百个单元我想连接成单个字符串。是否有比这更简单的方法,而不是手动将它们逐一打入CONCATENATE(A1, A2, ....)
?在Excel中的批处理字符串连接
CONCATENATE(A1:A255)
不起作用。
我在Excel中有几百个单元我想连接成单个字符串。是否有比这更简单的方法,而不是手动将它们逐一打入CONCATENATE(A1, A2, ....)
?在Excel中的批处理字符串连接
CONCATENATE(A1:A255)
不起作用。
*在一个新的选项卡,在单元格A1型A1,在细胞
* A2型A2
*使用填充序列来完成在列中的值甲
* A1型细胞B1
使用此forumal在单元格B2
= B1 & “” & A2
复印式向下。
复制并粘贴值以收集您创建的值的字符串。
A1 A1
A2 A1,A2
A3 A1,A2,A3
A4 A1,A2,A3,A4
A5 A1,A2,A3,A4,A5
A6 A1,A2,A3,A4,A5,A6
A7 A1,A2,A3,A4,A5,A6,A7
A8 A1,A2,A3,A4,A5,A6,A7,A8
A9 A1,A2,A3,A4,A5,A6,A7,A8,A9
A10 A1,A2,A3,A4,A5,A6,A7,A8,A9,A10
如果需要,此VBA函数将连接单元格的内容和可选的分隔符。它复制到一个标准模块:
Option Explicit
Function Concat(CellRange As Range, Optional Delimiter As String) As String
' this function will concatenate a range of cells and return the result as a single string
' useful when you have a large range of cells that you need to concatenate
' source: http://chandoo.org/wp/2008/05/28/how-to-add-a-range-of-cells-in-excel-concat/
Dim retVal As String, dlm As String, cell As Range
retVal = ""
If Delimiter = Null Then
dlm = ""
Else
dlm = Delimiter
End If
For Each cell In CellRange
If CStr(cell.Value) <> "" And CStr(cell.Value) <> " " Then
retVal = retVal & CStr(cell.Value) & dlm
End If
Next
If dlm <> "" Then
retVal = Left(retVal, Len(retVal) - Len(dlm))
End If
Concat = retVal
End Function
串连(A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15,A16,A17,A18,A19,A20 a21 a22 a23 a24 a25 a26 a27 a28 a29 a30 a31 a32 a33 a34 a35 a36 a37 a38 a39 a40 a41 a42 a43 a44 a45 a46 a47 a48 a49 a50 a51 a52 a53 a54 a55 a56 a57 a58 a59 a60 a61 a62 a63 a64 a65 a66 a67 a68 a69 a70 a71 a72 a73 a74 a75 a76 a77 a78 a79 a80 a81 a82 a83 a84 a85 a86 a87 a88 a89 a90 a91 a92 a93 a94 a95 a96 a97 a98 a99 a100 a101 a102 a103 a104 a105 a106 a107 a108 a109 a110 a111 a112 a113 a114 a115 a116 a117 a118 a119 a120 a121 a122 a123 a124 a125 a126 a127 a128 a129 a130 a131 a132 a133 a134 a135 a136 a137 a138 ,A139,A140,A141,A142,A143,A144,A145,A146,A147,A148,A149,A150,A151,A152,A153,A154,A155,A156,A157,A158,A159,A160,A161,A162,A163 ,A164,A165,A166,A167,A168,A169,A170,A171,A172,A173,A174,A175,A176,A177,A178,A179,A180,A181,A182,A183,A184,A185,A186,A187,A188 a199 a190 a191 a192 a193 a194 a195 a196 a197 a198 a199 a200 a201 a202 a203 a204 a205 a206 a207 a208 a209 a210 a211 a212 a213 a214 a215 a216 a217 a218 a219 a220 a221 a222 a223 a224 a225 a226 a227 a228 a229 a230 a231 a232 a233 a234 a235 a236 a237 a238 ,A239,A240,A241,A242,A243,A244,A245,A246,A247,A248,A249,A250,A251,A252,A253,A254,A255)
PowerShell的吧!
"concatenate(a$((1..255) -join ', a'))" | clip
打开文本文件复制粘贴
看到这个博客张贴在这里:http://www.dullsharpness.com/2011/11/14/excel-vba-range-to-csv-range2csv-function/
您可以使用它像这样,例如用竖线分隔符:使用Alt+F11
拖放到一个模块
=Range2Csv(A1:A255,"|")
访问您的VBA编辑器。
代码摘录是在这里:
Option Explicit
'**********************************************
'* PURPOSE: Concatenates range contents into a
'* delimited text string
'*
'* FUNCTION SIGNATURE: Range2Csv(Range, String)
'*
'* PARAMETERS:
'* Range - the range of cells whose contents
'* will be included in the CSV result
'* String - delimiter used to separate values
'* (Optional, defaults to a comma)
'*
'* AUTHOR: www.dullsharpness.com
'*
'* NOTES: [add'l notes removed for brevity]
'*
'**********************************************
Public Function Range2Csv(inputRange As Range, Optional delimiter As String)
Dim concattedList As String 'holder for the concatted CSVs
Dim rangeCell As Range 'holder cell used in For-Each loop
Dim rangeText As String 'holder for rangeCell's text
'default to a comma delimiter if none is provided
If delimiter = "" Then delimiter = ","
concattedList = "" 'start with an empty string
'Loop through each cell in the range to append valid contents
For Each rangeCell In inputRange.Cells
rangeText = rangeCell.Value 'capture the working value
'Only operate on non-blank cells (i.e. Length > 0)
If Len(rangeText) > 0 Then
'Strip any delimiters contained w/in the value itself
rangeText = WorksheetFunction.Substitute(rangeText, delimiter, "")
If (Len(concattedList) > 0) Then
'prepend a delimiter to the new value if we
'already have some list items
concattedList = concattedList + delimiter + rangeText
Else
'else if the list is blank so far,
'just set the first value
concattedList = rangeText
End If
End If
Next rangeCell
'Set the return value
Range2Csv = concattedList
End Function
如果您寻找一个纯粹的Excel的方法(即没有VBA),然后由詹姆斯·詹金斯提出的方法是最好的。 如果您在使用VBA然后打开VBA编辑器很高兴,添加一个新的模块,并添加以下代码:
Option Explicit
Public Function JoinText(cells As Variant,Optional delim_str As String) As String
If cells.Columns.count < cells.Rows.count Then
JoinText = Join(WorksheetFunction.Transpose(cells), delim_str)
Else
JoinText = Join(WorksheetFunction.Transpose(WorksheetFunction.Transpose(cells)), delim_str)
End If
End Function
要打开VBA编辑器轻松按下Alt-F11。 要插入模块,请右键单击“项目”窗口中列出的工作簿。
功能是从Excel称为如下:
=JoinText(A1:C1)
如果你想添加一个分隔符(如逗号):
=JoinText(A1:C1,",")
使用转功能的目的是把二维数组,“细胞”,到一维数组中。对此的共鸣是,VBA函数Join只接受一个1d数组。 使用其中两个的原因是,如果JoinText正在查看一行单元格(它仍然只是一个2d数组),那么第一次调用转置,将此2d行数组转换为2d列数组,第二次调用将它转换为成1d阵列。
我的首选方法是剪切和粘贴值到一个编辑器,允许正则表达式,那么我只是删除了查找选项卡(或空格),并在我的当前选择替换。
你也可以用它来插入逗号,空格或任何你想要的。
这是一个吨比打字=concatenate(A1,",","A2",",",......)
我喜欢TextPad(免费软件)。 - 点击F8以打开“查找/替换”对话框。-check the box'use regular expression' -FIND:\ n REPLACE:, – bkwdesign 2014-05-01 14:54:55
它不是纯粹的Excel的速度更快,但有一个简单的方法与Word做到这一点。
那里,你想concantenate在您的工作表
的行2列3日开始的值Sub GOWN()
roww = 2
Do While cells(roww, 2) <> ""
aa = cells(roww, 3)
dd = dd & aa & ","
roww = roww + 1
Loop
cells(roww + 1, 3) = dd
End Sub
按Alt-F11
,插入新模块,粘贴代码如下。
Public Function concatRange(data As Range, Optional sep As String = "") As String
Dim ret As String
Dim sep2 As String
ret = ""
sep2 = ""
For Each cell In data
ret = ret & sep2 & cell.Value
sep2 = sep
Next cell
concatRange = ret
End Function
用法:
=concatRange(A8:D11;", ") 'OS with ; list separator
=concatRange(A8:D11,", ") 'OS with , list separator or in a macro code
或
=concatRange(A8:D11)
只需添加您的deliminator在一个串联:
=concatenate(A1, ",")
然后复制所有的串连,将其粘贴为值。然后复制这些值,将它们粘贴在一个换位符中。然后复制Transposed值并将它们粘贴到文字编辑器中。做一个查找的定界符和值之前的空格,并替换为JUST的定界符。这应该给你一个连接字符串的所有值与一个分隔符。这比其他选项容易得多。
如果您有Excel 2016,则可以使用阵列式:
输入
= CONCAT(A1:A255)
进入细胞内,然后按
[ctrl] + [shift] + [enter]
实际上,不需要输入数组公式,CONCAT()接受一个数组输入但返回一个字符串,所以你只需要点击输入 – Greedo 2017-04-03 14:34:35
无耻地从this site复制:
- 选择您所需要的结果的单元格。
- 转到公式栏并输入...“= A1:A5”
- 选择整个公式并按F9(将公式转换为值)。
- 从两端取下大括号。
- Add = CONCATENATE(到文本的开头并用圆括号结束)。
- 按Enter键。
什么特别启示这里是编辑公式时,按下F9键替换与公式的结果公式。如果这是一个范围,它会用该范围内容的列表替换它。
有可能使用vb来做到这一点。 你想要搜索的是“在excel中连接一个范围” – loosebazooka 2013-02-28 20:19:15
有些方法可以在没有VBA的情况下完成它:http://www.get-digital-help.com/2011/02/09/concatenate- a-cell-range-without-vba-in-excel/ – 2013-02-28 20:43:11
Split和Join是Excel中缺少的两个明显功能。非常令人沮丧。 – 2016-09-01 00:44:41