Excel精英培训网

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

[已解决]排列

[复制链接]
发表于 2021-1-14 18:37 | 显示全部楼层 |阅读模式
本帖最后由 c888 于 2021-1-15 20:10 编辑

谢谢!
最佳答案
2021-1-15 14:25
本帖最后由 cutecpu 于 2021-1-15 14:26 编辑

Sub demo()

   Sheets("表1").Select: arr = Range("A1").CurrentRegion
   Sheets("表2").Select: Range("A1").CurrentRegion.Clear
   Columns("A:H").Select: Selection.NumberFormatLocal = "@"
   
   For i = 2 To UBound(arr, 1)
      If arr(i, 1) <> class Then
         class = arr(i, 1)
         r = r + 2
         Cells(r, 1).Value = arr(i, 1)
         r = r + 1
         Cells(r, 1).Value = "班主任": Cells(r, 2).Value = arr(i, 6)
         Cells(r + 1, 1).Value = "运动员"
       End If
   
      If arr(i, 5) <> gender Then
         gender = arr(i, 5)
         r = r + 2: c = 1
         Cells(r, 1).Value = arr(i, 5)
      End If
   
      If c = 8 Then c = 1: r = r + 2
      c = c + 1
      Cells(r, c).Value = arr(i, 2)
      Cells(r + 1, c).Value = arr(i, 3)
   Next
   Range("A2").Select
   
End Sub
祝順心,南無阿彌陀佛!

排列.zip

11.59 KB, 下载次数: 13

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
 楼主| 发表于 2021-1-15 13:58 | 显示全部楼层
回复

使用道具 举报

 楼主| 发表于 2021-1-15 14:00 | 显示全部楼层
回复

使用道具 举报

发表于 2021-1-15 14:25 | 显示全部楼层    本楼为最佳答案   
本帖最后由 cutecpu 于 2021-1-15 14:26 编辑

Sub demo()

   Sheets("表1").Select: arr = Range("A1").CurrentRegion
   Sheets("表2").Select: Range("A1").CurrentRegion.Clear
   Columns("A:H").Select: Selection.NumberFormatLocal = "@"
   
   For i = 2 To UBound(arr, 1)
      If arr(i, 1) <> class Then
         class = arr(i, 1)
         r = r + 2
         Cells(r, 1).Value = arr(i, 1)
         r = r + 1
         Cells(r, 1).Value = "班主任": Cells(r, 2).Value = arr(i, 6)
         Cells(r + 1, 1).Value = "运动员"
       End If
   
      If arr(i, 5) <> gender Then
         gender = arr(i, 5)
         r = r + 2: c = 1
         Cells(r, 1).Value = arr(i, 5)
      End If
   
      If c = 8 Then c = 1: r = r + 2
      c = c + 1
      Cells(r, c).Value = arr(i, 2)
      Cells(r + 1, c).Value = arr(i, 3)
   Next
   Range("A2").Select
   
End Sub
祝順心,南無阿彌陀佛!

demo.rar

20.71 KB, 下载次数: 4

回复

使用道具 举报

 楼主| 发表于 2021-1-18 16:26 | 显示全部楼层
http://www.excelpx.com/forum.php ... &extra=page%3D1
老师请帮忙指教,与前次排列有点相似。谢谢!
回复

使用道具 举报

发表于 2021-1-18 19:32 | 显示全部楼层
cutecpu 发表于 2021-1-15 14:25
Sub demo()

   Sheets("表1").Select: arr = Range("A1").CurrentRegion

学习了,学习了
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-26 05:51 , Processed in 0.241404 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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