Excel精英培训网

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

[已解决]请问怎如何通过VBA插入指定行?

[复制链接]
发表于 2012-1-4 07:35 | 显示全部楼层 |阅读模式
比如D1=3 按下开关 就在第三行后插入一行空白的 上下的公式内容都不变
输入D1=5 就在第五行后插入

D1是一个根据根据其他格变化的数

菜鸟啊.....谢谢大家!!!!
最佳答案
2012-1-4 07:57
  1. Private Sub Worksheet_Change(ByVal Target As Range)
  2. If Target.Count > 1 Then Exit Sub
  3. If Target.Address <> "$D$1" Then Exit Sub
  4. Cells(Target.Value + 1, 1).EntireRow.Insert shift:=xlDown
  5. End Sub
复制代码
可用工作表变化事件试试看。

评分

参与人数 1 -2 收起 理由
Select -2 不见楼主回复

查看全部评分

发表于 2012-1-4 07:55 | 显示全部楼层
本帖最后由 sunjing-zxl 于 2012-1-4 08:05 编辑

  1. Sub 插入()
  2.     Dim Ro As Long
  3.     Ro = [D1]   
  4.     Rows(Ro).Insert
  5. End Sub
复制代码

回复

使用道具 举报

发表于 2012-1-4 07:57 | 显示全部楼层    本楼为最佳答案   
  1. Private Sub Worksheet_Change(ByVal Target As Range)
  2. If Target.Count > 1 Then Exit Sub
  3. If Target.Address <> "$D$1" Then Exit Sub
  4. Cells(Target.Value + 1, 1).EntireRow.Insert shift:=xlDown
  5. End Sub
复制代码
可用工作表变化事件试试看。
回复

使用道具 举报

发表于 2012-1-4 08:33 | 显示全部楼层
本帖最后由 雄鹰 于 2012-1-4 08:48 编辑

Sub 插入指定行()
     Rows(Range("d1")+1).Select
     Selection.Insert Shift:=xlDown
End Sub
回复

使用道具 举报

发表于 2012-1-4 08:41 | 显示全部楼层
本帖最后由 雄鹰 于 2012-1-4 08:46 编辑

Sub 插入指定行2()
     Rows([d1]+1).Insert
End Sub
回复

使用道具 举报

发表于 2012-1-4 08:43 | 显示全部楼层
本帖最后由 雄鹰 于 2012-1-4 08:44 编辑
sunjing-zxl 发表于 2012-1-4 07:55


一句代码解决问题!{:211:}
强!
回复

使用道具 举报

发表于 2012-1-4 09:07 | 显示全部楼层
楼上的都是高手啊~~~~~~~~~
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-20 02:35 , Processed in 0.318454 second(s), 13 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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