ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
12
返回列表 发新帖
楼主: newlove

[求助] 将数据中的内容按模板输出

[复制链接]

TA的精华主题

TA的得分主题

 楼主| 发表于 2020-11-4 13:58 | 显示全部楼层
orr89 发表于 2020-11-4 11:24
Sub 排列()

    Sheet1.Activate

感谢你!辛苦你了!

TA的精华主题

TA的得分主题

发表于 2020-11-4 19:51 | 显示全部楼层
newlove 发表于 2020-11-4 13:58
感谢你!辛苦你了!

Sub 排列()
   
    Sheet1.Activate
    Sheet1.Range("A2:H" & Sheet1.[a60000].End(xlUp).Row).Select
    With Sheet1.Sort
        With .SortFields
            .Clear
            .Add Key:=Range("H2:H" & Sheet1.[a60000].End(xlUp).Row), SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:=""
        End With
        .Header = xlNo
        .Orientation = xlSortColumns
        .MatchCase = False
        .SortMethod = xlPinYin
        .SetRange Rng:=Selection
        .Apply
    End With '辅助列乱序
   
    arr = Sheet1.Range("a1").CurrentRegion
   
    Sheet3.Activate
    With Sheet3
        .Cells.Clear
        lie = 1
        zu = 1
        hang = 2
        For 项目列 = 5 To 7
            If .Cells(.[b60000].End(xlUp).Row, "B") = "" Then
                .Cells(.[b60000].End(xlUp).Row, "A") = arr(2, 4)
                .Cells(.[b60000].End(xlUp).Row, "B") = arr(1, 项目列)
            Else
                .Cells(.[b60000].End(xlUp).Row + 2, "A") = arr(2, 4)
                .Cells(.[b60000].End(xlUp).Row + 2, "B") = arr(1, 项目列)
                hang = hang + 2
                zu = 1
                lie = 1
            End If
            For a = 2 To UBound(arr)
                If arr(a, 项目列) <> "" Then
                    lie = lie + 1
                    If lie = 8 Then
                        lie = 2
                        hang = hang + 3
                        zu = zu + 1
                    End If
                    .Cells(hang, 1) = zu & "组"
                    .Cells(hang, lie) = lie - 1 & "道"
                    .Cells(hang + 1, lie) = arr(a, 3)
                    .Cells(hang + 2, lie) = arr(a, 项目列)
                End If
            Next
            hang = .[b60000].End(xlUp).Row
            For 反查 = hang To 1 Step -3
                If Cells(反查 - 2, "E") <> "" Then
                    Exit For
                Else
                    For 反查1 = 5 To 2 Step -1
                        If Cells(反查 - 2, 反查1) <> "" Then
                            Exit For
                        Else
                            Range(Cells(反查 - 5, 反查1 + 2), Cells(反查 - 3, 反查1 + 2)).Copy
                            Cells(反查 - 2, 反查1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                                :=False, Transpose:=False
                            Range(Cells(反查 - 5, 反查1 + 2), Cells(反查 - 3, 反查1 + 2)).ClearContents
                        End If
                    Next 反查1
                End If
            Next
        Next
    End With
   
End Sub '增加了每组必须大于3人的需求,仅供参考,自己修修改改吧.

您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-5-20 22:57 , Processed in 0.025335 second(s), 9 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表