Excel精英培训网

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

[已解决]测试“插入空列”代码

[复制链接]
发表于 2014-5-11 11:40 | 显示全部楼层 |阅读模式
本帖最后由 642070295 于 2014-5-11 13:07 编辑

麻烦高手帮看一下,运行代码后发现最后面的区域没有按要求效果插入空列(要求效果是:每3列数据插入一列空列),为什么呢?怎么纠正代码?    先谢了! 附件.rar (17.76 KB, 下载次数: 11)
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2014-5-11 12:05 | 显示全部楼层
  1. Sub Macro1()
  2. Dim rng As Range, i&
  3. Application.ScreenUpdating = False
  4. For i = 4 To Cells(1, Columns.Count).End(xlToLeft).Column Step 3
  5.     If rng Is Nothing Then Set rng = Cells(1, i) Else Set rng = Union(rng, Cells(1, i))
  6. Next
  7. If Not rng Is Nothing And Cells(1, 4) <> "" Then rng.EntireColumn.Insert Shift:=xlToRight
  8. Application.ScreenUpdating = True
  9. End Sub
复制代码
回复

使用道具 举报

发表于 2014-5-11 12:27 | 显示全部楼层    本楼为最佳答案   
Private Sub CommandButton1_Click()
    Dim j%
    With Sheets(2)
        For j = .Range("d1").End(2).Column + 1 To 3 Step -3
            .Columns(j).Insert Shift:=xlToRight
        Next j
    End With
End Sub

回复

使用道具 举报

 楼主| 发表于 2014-5-11 13:06 | 显示全部楼层
谢谢了,问题已解决!
回复

使用道具 举报

发表于 2014-5-11 14:08 | 显示全部楼层
进来游览下代码!
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-31 07:18 , Processed in 0.351832 second(s), 15 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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