在Excel中将多行合并到一行中
我想使用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个电话的信息。
有谁知道如何在Excel上做到这一点? 我真的很感谢帮助。
最好的祝福
这段代码应该这样做,巩固起来,并删除多余的行
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