全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 Excel
1590 2
2012-04-27
如何利用VBA将原表中的数据转换为结果表形式的数据?
说明:1.这样的数据有上万行
2.需要将一个分公司里的相同部门放在一起
3.在部门行位置变动的同时其他信息也应该跟着变动位置
4.变动后同一个分公司中的的相同部门进行合并
5.最终结果如结果表
详见附件
谢谢
附件列表

vba行移动再合并.rar

大小:4.56 KB

 马上下载

本附件包括:

  • vba行移动再合并.xls

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2016-6-28 17:02:32
Sub 排序合并()
    Dim i As Long, j As Long
    Dim d As Object
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Set d = CreateObject("scripting.dictionary")
    i = Range("a1").CurrentRegion.Rows.Count
    Range("a1:a" & i).UnMerge
    For j = 2 To i
        If Cells(j, 1) = "" Then
            Cells(j, 1) = Cells(j - 1, 1)
        Else
            d(Cells(j, 1).Value) = ""
        End If
    Next
    Application.AddCustomList listarray:=d.keys
    Range("a1").CurrentRegion.Sort key1:=Range("a1"), order1:=xlAscending, OrderCustom:=Application.CustomListCount + 1, key2:=Range("b1"), order2:=xlAscending, Header:=xlGuess
    Application.DeleteCustomList Application.CustomListCount
    For j = i To 2 Step -1
        If Cells(j, 1) = Cells(j - 1, 1) And Cells(j, 2) = Cells(j - 1, 2) Then
            Range(Cells(j - 1, 2), Cells(j, 2)).Merge
        End If
        If Cells(j, 1) = Cells(j - 1, 1) Then
            Range(Cells(j - 1, 1), Cells(j, 1)).Merge
        End If
    Next
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
End Sub
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2016-6-28 17:03:03
Sub 排序合并()
    Dim i As Long, j As Long
    Dim d As Object
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Set d = CreateObject("scripting.dictionary")
    i = Range("a1").CurrentRegion.Rows.Count
    Range("a1:a" & i).UnMerge
    For j = 2 To i
        If Cells(j, 1) = "" Then
            Cells(j, 1) = Cells(j - 1, 1)
        Else
            d(Cells(j, 1).Value) = ""
        End If
    Next
    Application.AddCustomList listarray:=d.keys
    Range("a1").CurrentRegion.Sort key1:=Range("a1"), order1:=xlAscending, OrderCustom:=Application.CustomListCount + 1, key2:=Range("b1"), order2:=xlAscending, Header:=xlGuess
    Application.DeleteCustomList Application.CustomListCount
    For j = i To 2 Step -1
        If Cells(j, 1) = Cells(j - 1, 1) And Cells(j, 2) = Cells(j - 1, 2) Then
            Range(Cells(j - 1, 2), Cells(j, 2)).Merge
        End If
        If Cells(j, 1) = Cells(j - 1, 1) Then
            Range(Cells(j - 1, 1), Cells(j, 1)).Merge
        End If
    Next
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
End Sub
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群