Excel精英培训网

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

[已解决]根据条件用vba批量插入标题

[复制链接]
发表于 2012-11-6 10:53 | 显示全部楼层 |阅读模式
请各位论坛老师帮忙写段代码。先谢了。
条件:
A3:A50有一中、二中或三中,只在三中的上一行插入一行并复制A2:L2的内容。
图: 未命名.jpg

附件: 绩统计表.rar (7.58 KB, 下载次数: 8)
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2012-11-6 12:26 | 显示全部楼层    本楼为最佳答案   
  1. Sub text()
  2. Application.ScreenUpdating = False '关闭屏幕刷新
  3. Dim i As Integer, arr(), l As Long
  4. arr = Range("a2:l2").Value
  5. l = Cells(Rows.Count, 1).End(3).Row
  6. i = 4
  7. Do While i <= l
  8.   If Cells(i, 1).Value = "三中" Then
  9.      Range("a" & i).EntireRow.Insert
  10.      Range("a" & i & ":l" & i).Value = arr
  11.          With Range("a" & i & ":l" & i).Interior
  12.         .ColorIndex = 36
  13.         .Pattern = xlSolid
  14.     End With
  15.      i = i + 1
  16.      l = l + 1
  17.   End If
  18.   i = i + 1
  19. Loop
  20. Application.ScreenUpdating = True '开启屏幕刷新
  21. End Sub
复制代码
试试这个看~~
回复

使用道具 举报

 楼主| 发表于 2012-11-6 14:16 | 显示全部楼层
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-6-1 23:50 , Processed in 0.114391 second(s), 11 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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