excel中有A,B两列数据,怎样将这两列的数据,进行首尾相连接,放在C列。要求A的尾数与B的首数相同时才连接

2024-12-25 20:41:22
推荐回答(4个)
回答1:

'可以用VBA实现
'Alt+F11打开VBA, 加入如下代码
Sub Macro3() '已验证
Dim iARow As Integer, iBRow As Integer
Dim iARowMax As Integer, iBRowMax As Integer
Dim iTarRow As Integer
Dim sA As String, sB As String

iARowMax = 1
While ActiveSheet.Cells(iARowMax, 1) <> ""
iARowMax = iARowMax + 1
Wend

iBRowMax = 1
While ActiveSheet.Cells(iBRowMax, 1) <> ""
iBRowMax = iBRowMax + 1
Wend

iTarRow = 1
For iARow = 1 To iARowMax - 1
sA = Right(ActiveSheet.Cells(iARow, 1), 1)
For iBRow = 1 To iBRowMax - 1
sB = Left(ActiveSheet.Cells(iBRow, 2), 1)
If sA = sB Then
ActiveSheet.Cells(iTarRow, 3) = "'" & ActiveSheet.Cells(iARow, 1) & _
Mid(ActiveSheet.Cells(iBRow, 2), 2)
iTarRow = iTarRow + 1
End If
Next iBRow
Next iARow

End Sub

回答2:

我感觉先分裂、再VLOOKUP、再合并,希望可以给你启发

回答3:

VLOOKUP显然不能满足复数个场合。此题需要VBA才行。

回答4:

看似很复杂的