Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 3335|回复: 4

[已解决]编排

[复制链接]
发表于 2021-1-18 16:22 | 显示全部楼层 |阅读模式
数据排列,谢谢老师指教!
最佳答案
2021-1-18 19:51
Sub demo()

   Sheets("數據").Select: arr = Range("A1").CurrentRegion
   Sheets("編排").Select: Range("A1").CurrentRegion.Clear
   Columns("A:G").Select: Selection.NumberFormatLocal = "@"
   r = -3
   For i = 2 To UBound(arr, 1)
      If arr(i, 2) <> class Or arr(i, 3) <> gender Or arr(i, 4) <> Item Or arr(i, 5) <> race Then
         class = arr(i, 2): gender = arr(i, 3): Item = arr(i, 4): race = arr(i, 5): Group = ""
         r = r + 5
         Cells(r, 1).Value = class & gender & Item & race
         r = r - 4
      End If

      If arr(i, 6) <> Group Then
         Group = arr(i, 6)
         r = r + 5: c = 1
         Cells(r, 1) = Group
         r = r + 1
      End If

      If c = 7 Then c = 1: r = r + 5
      If c = 1 Then
         Cells(r + 0, 1) = "道次"
         Cells(r + 1, 1) = "號碼"
         Cells(r + 2, 1) = "姓名"
         Cells(r + 3, 1) = "班級"
         Cells(r + 4, 1) = "備註"
      End If

      c = c + 1
      Cells(r + 0, c) = arr(i, 7)
      Cells(r + 1, c) = arr(i, 8)
      Cells(r + 2, c) = arr(i, 9)
      Cells(r + 3, c) = arr(i, 10)

   Next
   Range("A2").Select

End Sub

祝順心,南無阿彌陀佛!

编排.zip

13.05 KB, 下载次数: 8

发表于 2021-1-18 19:31 | 显示全部楼层
回复

使用道具 举报

发表于 2021-1-18 19:51 | 显示全部楼层    本楼为最佳答案   
Sub demo()

   Sheets("數據").Select: arr = Range("A1").CurrentRegion
   Sheets("編排").Select: Range("A1").CurrentRegion.Clear
   Columns("A:G").Select: Selection.NumberFormatLocal = "@"
   r = -3
   For i = 2 To UBound(arr, 1)
      If arr(i, 2) <> class Or arr(i, 3) <> gender Or arr(i, 4) <> Item Or arr(i, 5) <> race Then
         class = arr(i, 2): gender = arr(i, 3): Item = arr(i, 4): race = arr(i, 5): Group = ""
         r = r + 5
         Cells(r, 1).Value = class & gender & Item & race
         r = r - 4
      End If

      If arr(i, 6) <> Group Then
         Group = arr(i, 6)
         r = r + 5: c = 1
         Cells(r, 1) = Group
         r = r + 1
      End If

      If c = 7 Then c = 1: r = r + 5
      If c = 1 Then
         Cells(r + 0, 1) = "道次"
         Cells(r + 1, 1) = "號碼"
         Cells(r + 2, 1) = "姓名"
         Cells(r + 3, 1) = "班級"
         Cells(r + 4, 1) = "備註"
      End If

      c = c + 1
      Cells(r + 0, c) = arr(i, 7)
      Cells(r + 1, c) = arr(i, 8)
      Cells(r + 2, c) = arr(i, 9)
      Cells(r + 3, c) = arr(i, 10)

   Next
   Range("A2").Select

End Sub

祝順心,南無阿彌陀佛!

demo.rar

11.61 KB, 下载次数: 8

回复

使用道具 举报

发表于 2021-1-18 20:00 | 显示全部楼层
cutecpu 发表于 2021-1-18 19:51
Sub demo()

   Sheets("數據").Select: arr = Range("A1").CurrentRegion

学习了学习了,清晰的思路,精练的表达
回复

使用道具 举报

 楼主| 发表于 2021-1-19 14:31 | 显示全部楼层
cutecpu 发表于 2021-1-18 19:51
Sub demo()

   Sheets("數據").Select: arr = Range("A1").CurrentRegion

谢谢您老师!就是要这个效果!
回复

使用道具 举报

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

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-18 22:20 , Processed in 0.326149 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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