我有一个连接两个相邻列中的值的宏。它完美地工作。我想添加一个命令,然后在连接完成后删除第二列。我可以从现有的子路由/宏内部执行此操作,还是需要调用单独的函数?这是我所拥有的:
Option Explicit
Sub Doc1_Doc2_Merge()
Dim CurrCol As Integer
Dim NewValue As String
CurrCol = 1
While Cells(1, CurrCol).Address <> "$JL$1"
'MsgBox Cells(1, CurrCol).Address & " " & Cells(1, CurrCol).Value
If InStr(Cells(1, CurrCol).Value, "Doc1") > 0 Then
' look at next cell
If InStr(Cells(1, CurrCol + 1).Value, "Doc2") > 0 Then
If Trim(Cells(2, CurrCol + 1).Value) <> "" Then
NewValue = Cells(2, CurrCol).Value & ", " & Cells(2, CurrCol + 1)
'MsgBox "New Value is " & NewValue
Cells(2, CurrCol).Value = NewValue
End If
End If
End If
'now delte currCol+1
'This is the deletion part that isn't working
Column(CurrCol + 1).Select
Selection.Delete Shift:=xlToLeft
'Advance the counter
CurrCol = CurrCol + 1
Wend
End Sub