0

我想使用 Excel 将几行合并为一行。我已经使用 CONCATENATE 函数完成了这项工作,但这次我需要自动化该过程,因为我在文件中有多个条目。我有从 Cisco CME 中提取的 Ephone IP 电话信息,其中每个 ephone 信息都在一行中,如下所示:

ephone-1[0] Mac: TCP socket:[57] activeLine:0 whisperLine:0 REGISTERED in SCCP ver 20/17 max_streams=1
mediaActive:0 whisper_mediaActive:0 startMedia:0 offhook:0 ringing:0 reset:0 reset_sent:0 paging 0 debug:0 caps:8 
IP:---------- * 35419 6941  keepalive 54113 max_line 4 available_line 4
button 1: cw:1 ccw:(0 0) 
dn 1  number ------- CH1   IDLE         CH2   IDLE         shared 
Preferred Codec: g711ulaw 
Lpcor Type: none Username: ---- Password: ------ 


ephone-2[1] Mac:-------- TCP socket:[77] activeLine:0 whisperLine:0 REGISTERED in SCCP ver 20/17 max_streams=1
mediaActive:0 whisper_mediaActive:0 startMedia:0 offhook:0 ringing:0 reset:0 reset_sent:0 paging 0 debug:0 caps:8 
IP:------- * 35189 6941  keepalive 117528 max_line 4 available_line 4
button 1: cw:1 ccw:(0 0) 
 dn 2  number ------ CH1   IDLE         CH2   IDLE         shared 
Preferred Codec: g711ulaw 
Lpcor Type: none 

每个 ephone 由文件上的一两个空行分隔。大约有 350 个条目,我想自动化这个过程。该过程应该类似于获取 ephone 的每一行并将其合并为一行,这样最后我将有 350 行包含 350 个 ephone 的信息。

有谁知道如何在Excel上制作这个?我非常感谢您的帮助。

此致

4

1 回答 1

2

这段代码应该这样做,合并并删除多余的行

Sub ConsolidateRows_NoMatch()
'takes rows and consolidate one or many cells, based on one or many cells matching with above or below rows.

Dim lastRow As Long, i As Long, j As Long
Dim colMatch As Variant, colConcat As Variant

'turn off updates to speed up code execution
With application
    .ScreenUpdating = False
    .EnableEvents = False
    .Calculation = xlCalculationManual
End With

lastRow = range("A" & Rows.Count).End(xlUp).Row 'get last row

For i = lastRow To 1 Step -1 'loop from last Row to one

    If Len(Cells(i, 1)) > 0 Then
        If Left(Cells(i, 1), 6) <> "ephone" Then
            Cells(i - 1, 1) = Cells(i - 1, 1) & Cells(i, 1)
        Else
            GoTo nxti:
        End If
    End If

    Rows(i).Delete
nxti:
Next

With application
    .ScreenUpdating = True
    .EnableEvents = True
    .Calculation = xlCalculationAutomatic
End With

End Sub
于 2012-10-15T15:49:16.330 回答