2017-10-10 116 views
-1

在电子表格中,我需要合并ABAB表单中单元格内的内容,其中每个单元格内的换行符都受到尊重。我需要为1000线做这个,所以需要一个简单的批量程序。如何在Google表格(或Excel)中水平地对单元格进行合并?

我需要维护当前行,因为以后CSV将用于批量替换到字幕文件 - 一次一个当前行。很多行继续包含与一个字幕文本字符串相关的所有数据。不过,我需要得到中间和左侧栏的内容从组合:

--cell one--  --cell two-- 

A1     B1 

A2     B2 

A3     B3 

--cell three--  --cell four-- 

C1     D1 

C2     D2 

C3     D3 

成所需的结果形式:

--cell one--  

A1(B1) 

A2(B2) 

A3(B3) 

--cell three--  

C1(D1)..... etc.... 
换句话说,这一切都在一个小区

所以:

niemniej (still) 
jednak (but) 
zgodził (he agreed) 
się udzielić (to grant) 
Kate (kate) 
wywiadu. (interview) 

google sheets translation word for word - SCREENSHOT

+0

VBA:使用'Split(cellText,vbLf)'从两个要连接的单元中的每一个单元创建数组。将两个数组“压缩”在一起循环并连接文本,然后合并单元格并用“压缩”版本替换文本。 –

回答

1
=ARRAYFORMULA(JOIN(CHAR(10),SPLIT(B12,CHAR(10))&"("&SPLIT(C12,CHAR(10))&")")) 

对于谷歌片在相应的值。加入B12 & C12

+1

难以置信的简单,我花了很多时间在错误的地方寻找一种方法!谢谢 –

1

它需要一些辅助列,但这里有一个没有VBA的解决方案。这要求您的数据从单元格A1开始,并且还要求每个单元格中的每行都是唯一的。它还要求Excel 2016或更高版本使用CONCAT功能。对小区C1

阵列式(必须使用CTRL + SHIFT + ENTER被保存):

=LEFT(CONCAT(OFFSET(D1,0,0,1,MATCH(TRUE,ISERROR(D1:W1),0)-1)),LEN(CONCAT(OFFSET(D1,0,0,1,MATCH(TRUE,ISERROR(D1:W1),0)-1)))-1)

公式细胞D1:

=LEFT(A1,FIND(CHAR(10),A1)-1)

公式细胞E1:

="("&LEFT(B1,FIND(CHAR(10),B1)-1)&")"&CHAR(10)

公式单元格F1:

=IFERROR(MID($A1,FIND(D1,$A1)+LEN(D1)+1,FIND(CHAR(10),$A1,FIND(D1,$A1)+LEN(D1)+1)-(FIND(D1,$A1)+LEN(D1)+1)),RIGHT($A1,LEN($A1)-(FIND(D1,$A1)+LEN(D1))))

公式单元格G1:

="("&IFERROR(MID($B1,FIND(MID(E1,2,LEN(E1)-3),$B1)+LEN(MID(E1,2,LEN(E1)-3))+1,FIND(CHAR(10),$B1,FIND(MID(E1,2,LEN(E1)-3),$B1)+LEN(MID(E1,2,LEN(E1)-3))+1)-(FIND(MID(E1,2,LEN(E1)-3),$B1)+LEN(MID(E1,2,LEN(E1)-3))+1)),RIGHT($B1,LEN($B1)-(FIND(MID(E1,2,LEN(E1)-3),$B1)+LEN(MID(E1,2,LEN(E1)-3)))))&")"&CHAR(10)

选择两个单元F1:G1,然后用填充柄两个公式拖到cell W1

这将处理每个单元最多10行。如果需要处理更多,请将助手公式拖到W1以上,并将单元格C1中公式中的W1的引用更新为拖动助手公式的位置。 (请记住,在每次编辑单元格C1中的数组公式时使用CTRL + SHIFT + ENTER进行保存。)

结果显示在单元格C1中。您需要手动将单元格C1的文本格式更改为Wrap Text以查看插入的换行符。

1

我试图字符串以定界符作为换行符(CHR(13))两者的列

分裂然后我级联每个阵列

Sub splitandconcatenate() 
Dim s1() As String, l1() As String 
Dim rowcount As Integer, currentRow As Integer 
Dim i As Integer 
Dim lookupRowValue As String, sourceRowvalue As String 
Dim sourceCol As Integer, CheckCol As Integer 

sourceCol = 1 ' 1 denotes Column A. Data in A column 
CheckCol = 2 ' 2 denotes Column B. Data in B column 
TargetCol = 3# ' 3 output is written in column c 
rowcount = Cells(Rows.Count, sourceCol).End(xlUp).Row 'counts the rows with data 

'For each row 
For currentRow = 1 To rowcount 
    sourceRowvalue = Cells(currentRow, sourceCol).Value 
    lookupRowValue = Cells(currentRow, CheckCol).Value 
'Split each cell with delimiter being newline chr(13) 
    s1 = Split(Chr(13) & sourceRowvalue, Chr(13)) 
    l1 = Split(Chr(13) & lookupRowValue, Chr(13)) 
'Two arrays are created for two columns. For each string in the array, concatenate the corresponding string in the other array 
     For i = 1 To UBound(s1) 
     Cells(currentRow, TargetCol).Value = Cells(currentRow, TargetCol).Value & Chr(13) & s1(i) & "(" & l1(i) & ")" 

     Next 
Next 
End Sub