首页  编辑  

转换竖向列表为横向列表

Tags: /计算机文档/Office/   Date Created:

转换竖向列表为横向列表:

例如类似下面的列表:

Computer DateTime        Handset DateTime        Event

07-11-21 09:25:51.529        07-11-21 09:25:51.529        Start Dial

07-11-21 09:25:52.881        07-11-21 09:25:52.881        Outgoing Call Attempt

07-11-21 09:25:58.619        07-11-21 09:25:58.619        Outgoing Call Established

07-11-21 09:27:04.534        07-11-21 09:27:04.534        Hangup Dial

07-11-21 09:27:04.654        07-11-21 09:27:04.654        Outgoing Call End

07-11-21 09:27:20.748        07-11-21 09:27:20.748        Start Dial

07-11-21 09:27:22.099        07-11-21 09:27:22.099        Outgoing Call Attempt

07-11-21 09:27:35.208        07-11-21 09:27:35.208        Outgoing Call Established

07-11-21 09:28:39.591        07-11-21 09:28:39.591        Hangup Dial

07-11-21 09:28:40.072        07-11-21 09:28:40.072        Outgoing Call End

07-11-21 09:28:55.804        07-11-21 09:28:55.804        Start Dial

07-11-21 09:28:57.547        07-11-21 09:28:57.547        Outgoing Call Attempt

07-11-21 09:28:59.169        07-11-21 09:28:59.169        Outgoing Call Attempt

07-11-21 09:28:59.940        07-11-21 09:28:59.940        Outgoing Call Attempt

07-11-21 09:29:56.762        07-11-21 09:29:56.762        Hangup Dial

07-11-21 09:30:13.566        07-11-21 09:30:13.566        Start Dial

07-11-21 09:30:14.648        07-11-21 09:30:14.648        Outgoing Call Attempt

07-11-21 09:30:21.738        07-11-21 09:30:21.738        Outgoing Call Established

07-11-21 09:31:26.080        07-11-21 09:31:26.080        Hangup Dial

07-11-21 09:31:26.321        07-11-21 09:31:26.321        Outgoing Call End

转换为:

Start Dial Outgoing Call Attempt Outgoing Call Established Hangup Dial Outgoing Call End Outgoing Blocked Call
07-11-21 09:25:51.529 07-11-21 09:25:52.881 07-11-21 09:25:58.619 07-11-21 09:27:04.534 07-11-21 09:27:04.654
07-11-21 09:27:20.748 07-11-21 09:27:22.099 07-11-21 09:27:35.208 07-11-21 09:28:39.591 07-11-21 09:28:40.072
07-11-21 09:28:55.804 07-11-21 09:28:57.547 07-11-21 09:29:56.762
07-11-21 09:30:13.566 07-11-21 09:30:14.648 07-11-21 09:30:21.738 07-11-21 09:31:26.080 07-11-21 09:31:26.321

' 请运行Excel后,按Alt+ F11,然后点菜单,插入--模块,把下面的代码复制到其中,以后就可以使用了。

' 请先复制需要转换的事件到Excel的某个Sheet中,然后按Alt + F8,选择 ConvertPioneerEventList 运行即可。

Sub ConvertPioneerEventList()

' 作者: Kingron

' 日期: 2007-12-23

' 说明: 转换Pioneer的详细拨打事件列表转换为横向的表格

 On Error Resume Next

 Dim DialFlow() ' 声明用于存储拨打的所有事件的定义的数组

 ' 初始化数组,请如果有更多的请参考下面的定义自己修改和添加

 ' 第一列用于标示新一行的,例如每次碰到 "Start Dial" 就在结果中添加一行!

 DialFlow = Array("Start Dial" _

                  , "Outgoing Call Attempt" _

                  , "Outgoing Call Established" _

                  , "Hangup Dial" _

                  , "Outgoing Call End" _

                  , "Outgoing Blocked Call" _

                  )

 

 Dim Source As Range  ' 源数据区域

 Dim DestCol As Integer ' 输出结果目标区的开始列

 Dim FlagCol As Integer  ' 标识列,和DialFlow中有同样数据的列

 Dim R As Range

 

 DestCol = ActiveSheet.UsedRange.Columns.Count + 1 ' 输出结果放在当前数据的最右边

 Set Source = ActiveSheet.UsedRange ' 求的当前的数据区域

 

 ' 生成结果区的表头

 iCol = DestCol

 For Each s In DialFlow

   ActiveSheet.Cells(1, iCol) = s

   iCol = iCol + 1

 Next

 ' 查找标识列

 For Each R In Source.Rows

   For FlagCol = 3 To R.Columns.Count

     If R.Columns(FlagCol).Text = "Event" Then GoTo Done

   Next

 Next

 

Done:

 ' 扫描并把所有结果存储到目标区域

 iRow = 1

 For Each R In Source.Rows  ' 扫描所有的源数据中的每一行

   If R.Columns(FlagCol).Value = DialFlow(0) Then iRow = iRow + 1  ' 如果碰到标识行,则新增加一行

   For i = LBound(DialFlow) To UBound(DialFlow) ' 扫描并查找到对应数组中的列

     ' 如果文本相同,并且结果目标区域中没有文本,也就是说该事件第一次碰到,则存储到目标结果

     If R.Columns(FlagCol).Text = DialFlow(i) And ActiveSheet.Cells(iRow, DestCol + i).Text = "" Then

       ActiveSheet.Cells(iRow, DestCol + i).NumberFormatLocal = "@"

       ActiveSheet.Cells(iRow, DestCol + i) = R.Columns(FlagCol - 2).Text

     End If

   Next

 Next

End Sub