注册 登录
编程论坛 VB6论坛

这代码合理吗?要怎么改

b198375 发布于 2022-09-28 20:29, 1530 次点击
Sub DELCO()
Dim i As Integer
i = 0
xunhuan:
On Error GoTo eend
Cells.Find(What:="关键字").Select     
Selection. EntireRow. Delete
Cells.Find(What:="关键字2").Select   
Selection. EntireRow. Delete
i = i + 1
GoTo xunhuan
eend:
MsgBox (i & "行被删除了")
End Sub

5 回复
#2
约定的童话2022-09-28 20:40
你是要放VB里面用还是直接在VBA里面用,两个有点区别哈
#3
b1983752022-09-28 21:28
回复 2楼 约定的童话
用在Excel里
#4
yuma2022-09-28 21:35
一看就是VBA宏
#5
zilaxiaolin2022-10-04 14:35
学习一下
#6
yuma2022-10-08 18:48
改了一下。这样比较合理。

程序代码:
Sub DELCO()
Dim i As Long, j As Long
j = 0
For i = 1 To 1048576  'Excel 2007的总行数
If Cells.Find("关键字6").Select = True Then
Selection.EntireRow.Delete
j = j + 1
End If

If Cells.Find("关键字7").Select = True Then
Selection.EntireRow.Delete
j = j + 1
End If

MsgBox "共删除了" & j & ""

Next
End Sub


[此贴子已经被作者于2022-10-8 18:53编辑过]

1