Excel精英培训网

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

一次拆分会,两次拆分不会,大侠们帮帮忙

[复制链接]
发表于 2021-5-6 11:51 | 显示全部楼层 |阅读模式
3学分
一次拆分会,两次拆分不会,大侠们帮帮忙
序号
地区
数量
序号
地区
数量
1
广东、福建、湖南、上海
3、6、5、8
1
广东
3
2
西藏
2
  
file:///C:/Users/27762/AppData/Local/Temp/msohtmlclip1/01/clip_image002.png
  
福建
4
3
云南、新疆、贵州
1、4、5
湖南
5
4
北京、河南
3、1
上海
8
2
西藏
2
3
云南
1
新疆
4
贵州
5
4
北京
3
河南
1

多次拆分.zip

7.9 KB, 下载次数: 4

发表于 2021-5-6 15:29 | 显示全部楼层
Range(Cells(2, 6), Cells([h10000].End(3).Row, 8)).Delete Shift:=xlUp       '删除原有表格
hs = 2   '从第2行开始显示,第1行是标题
For i = 2 To [a10000].End(3).Row
    s1 = Split(Cells(i, 2), "、")
    s2 = Split(Cells(i, 3), "、")
    js = hs
    For k = 0 To UBound(s1)
        If k = 0 Then
           Cells(hs, 6) = Cells(i, 1)
        End If
        Cells(hs, 7) = s1(k)
        Cells(hs, 8) = s2(k)
        hs = hs + 1
    Next k
    If UBound(s1) > 0 Then
       Range(Cells(js, 6), Cells(hs - 1, 6)).Merge    '大于1个单位就合并单元格
    End If
Next i

Range(Cells(2, 6), Cells([h10000].End(3).Row, 8)).Select    '下面是划表格线,在录制宏基础上简化而来
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlContinuous
Selection.Borders(xlEdgeTop).LineStyle = xlContinuous
Selection.Borders(xlEdgeBottom).LineStyle = xlContinuous
Selection.Borders(xlEdgeRight).LineStyle = xlContinuous
Selection.Borders(xlInsideVertical).LineStyle = xlContinuous
Selection.Borders(xlInsideHorizontal).LineStyle = xlContinuous
Range("f1").Select


回复

使用道具 举报

发表于 2021-5-19 11:58 | 显示全部楼层
用艾敦制表神器插件数据行拆分一键解决  

https://www.aidunsoft.com/photo/show-76.html
2.png
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-3 17:45 , Processed in 0.269653 second(s), 9 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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