Excel精英培训网

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

[VBA] 单元格数字连续

[复制链接]
发表于 2014-7-7 09:14 | 显示全部楼层 |阅读模式
  1. Sub 使单元格标号顺序连续()
  2. Dim a As Integer, b As Integer, c As Integer
  3. On Error Resume Next
  4. For a = 2 To 535
  5. If Cells(a + 1, 1) - Cells(a, 1) <> 1 Then
  6.    b = Cells(a + 1, 1) - Cells(a, 1) - 1
  7.    If b < 0 Then
  8.     Cells(a + 1, 1) = Cells(a, 1) + 1
  9.    End If
  10.    c = a + 1
  11.    Rows(c).Resize(b).Insert
  12.   Cells(a + 1, 1) = Cells(a, 1) + 1
  13.    End If
  14.     Next
  15. End Sub
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-8 00:15 , Processed in 0.190665 second(s), 6 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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