vba 使用多列的宏连接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25987155/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using macro Concatenation of Multiple Columns
提问by user3801227
please anybody help in concatenating cells using Excel 2007 macro. I have columns A to E. I want to concatenate all the Columns in column F. Please note that I don't know the exact number of rows in the all the Columns, but macro should stop concatenating when there are no values in the said columns. Sample:
请任何人帮助使用 Excel 2007 宏连接单元格。我有 A 到 E 列。我想连接 F 列中的所有列。请注意,我不知道所有列中的确切行数,但是当所述列中没有值时,宏应该停止连接列。样本:
A B C D E F O ABC DEF GHI E OABCDEFGHIE O JKL MNO PQR E OJKLMNOPQRE O STU VWXYZ E OVWXYZE
采纳答案by sabhareesh
May be you can try with the following code:
也许您可以尝试使用以下代码:
Sub concat()
Dim i As Integer
For i = 1 To ActiveSheet.UsedRange.Rows.Count
For j = 1 To 1
If (Cells(i, j).Value <> "") And (Cells(i, j + 1).Value <> "") And (Cells(i, j + 2).Value <> "") Then
Sheets("Sheet1").Range("D" & i).Value = Cells(i, j).Value + Cells(i, j + 1).Value + Cells(i, j + 2).Value
Else
Sheets("Sheet1").Range("D" & i).Value = "Empty cell found"
End If
Next j
Next i
End Sub
It may look long but i hope you ll get some idea...
它可能看起来很长,但我希望你能得到一些想法......
回答by Paresh J
You can simply use excel formula CONCATENATE, check the below line:
您可以简单地使用 excel 公式CONCATENATE,检查以下行:
Use this formula in column F =CONCATENATE(A1,B1,C1,D1,E1)
在列 F =CONCATENATE(A1,B1,C1,D1,E1) 中使用此公式
回答by Thuruv
Set a column to put the formula which is in next to the most significant cell. .
设置一列将公式放在最重要的单元格旁边。.
=Concatenate($A1:$somecell1)
= 连接($A1:$somecell1)
Here you need not toworry about the exact cell nums.
在这里您无需担心确切的单元格编号。