ExcelVBA删除包含指定字符所在的行 |
---|
=====相关====
=====end====
【问题】
例子:相类似的问题也可以哦今天有人提出这样子一个问题他有很多个工作表成绩表,想删除“缺考”的字符所在的行 |
---|
【思路】
用Find、FindNext找到“缺考“的行,再union再删除 |
---|
【代码】
Sub yhd_ExcelVBA删除包含指定字符所在的行()
Dim sht As Worksheet, s As String
s = "缺考"
For Each sht In Worksheets
Debug.Print sht.Name
Call DelInStrRow(sht, s)
Next sht
End Sub
Sub DelInStrRow(ThisSht As Worksheet, FindStr As String)
Dim myR As Range, myRngs As Range, myStr As String, firstAddress As String
With ThisSht
Set myRngs = .Rows(.Rows.Count)
Set myR = .Cells.Find(FindStr)
If Not myR Is Nothing Then
firstAddress = myR.Address
Do
Debug.Print myR.Row
Set myRngs = Union(myRngs, .Rows(myR.Row))
Set myR = .Cells.FindNext(myR)
Loop While Not myR Is Nothing And myR.Address <> firstAddress
myRngs.Delete
' .Range("a2").Select
Set myR = Nothing
Set myRngs = Nothing
End If
End With
End Sub
【效果】
一键完成,清理 |
---|
=====学习笔记=====