|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
DZ潇潇 发表于 2014-1-19 22:18 
方法笨了点,请别见笑。
公式的思路不错,不过涉及到单元格对象的位移操作,还是VBA来得更方便快捷。
下面提供两个问题的VBA解决思路——- Option Explicit
- Sub 插入指定空行()
- On Error Resume Next '错误处理
- Dim i%, j%
- i = 1 '定义计数器初始值,从第2行开始扫描
- j = 4 '插入空行数
- Application.ScreenUpdating = False '关闭屏幕刷新
- With ActiveSheet
- Do While Len(.Cells(i, 1)) <> 0 '循环处理条件,到最后一个不为空的单元格为止
- i = i + 1 '循环计数器步长+1
- If Not IsNumeric(.Cells(i, 1)) Then '判断是否为标题,是标题则插入空行
- Range(.Cells(i, 1), .Cells(i + j - 1, 1)).EntireRow.Insert Shift:=xlDown '插入指定空行数
- i = i + j '循环计数器增加空行数
- End If
- Loop
- End With
- Application.ScreenUpdating = True '打开屏幕刷新
- End Sub
- Sub 选择非空单元格()
- On Error Resume Next '错误处理
- With Selection
- Union(.SpecialCells(xlCellTypeConstants), .SpecialCells(xlCellTypeFormulas)).Select
- End With
- End Sub
复制代码 |
|