下面的代码使用一个范围从工作表中删除行,我的worbook没有标准化,所以我的问题是如何在这里使用InStr函数也删除类似的值,即如果“苹果有限公司”在范围内,那么它会删除包含“苹果”的行或反之亦然......是否有可能?使用InStr函数来删除范围内的相似值
更新:第28行:需要object @freeman我无法获得“Dim Cel as Range”的工作,我已经插入到这里并在工作表的顶部插入了相同的结果。你写的'Cel'的语法是?下面
Sub Loop_Example()
Dim ChkRange As Range
Dim Firstrow As Long
Dim Lastrow As Long
Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long
Set ChkRange = Sheets("Sheet2").Range("A1:A13")
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
With Sheet1
.Select
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView
.DisplayPageBreaks = False
Firstrow = 2
Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
For Lrow = Lastrow To Firstrow Step -1
With .Cells(Lrow, "A")
If Not IsError(.Value) Then
If Not IsError(Application.Match(.Value, ChkRange, 0)) Then
.EntireRow.Delete
End If
For Each Cell In ChkRange
If InStr(1, Cell.Value, .Value) > 0 And Cell.Value <> .Value Then
'include the 2nd part of the "AND" to ensure you don't delete based
'on a COMPLETE match, only on a partial match as noted in the comments
Cell.EntireRow.Delete
End If
Next
End If
End With
Next Lrow
End With
ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub
Sub Loop_Example()
Dim ChkRange As Range
Dim Firstrow As Long
Dim Lastrow As Long
Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long
Set ChkRange = Sheets("Sheet2").Range("A1:A13")
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
With Sheet1
.Select
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView
.DisplayPageBreaks = False
Firstrow = 2
Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
For Lrow = Lastrow To Firstrow Step -1
With .Cells(Lrow, "A")
If Not IsError(.Value) Then
If Not IsError(Application.Match(.Value, ChkRange, 0)) Then
.EntireRow.Delete
End If
For Each Cell In ChkRange
Dim Cel As Range
If InStr(1, Cell.Value, .Value) > 0 And Cell.Value <> .Value Then
'include the 2nd part of the "AND" to ensure you don't delete based
'on a COMPLETE match, only on a partial match as noted in the comments
Cell.EntireRow.Delete
End If
Next
End If
End With
Next Lrow
End With
ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub
菠萝是否算作像苹果公司? – pnuts 2015-04-02 14:44:08
如果整个值存在于另一个字符串中,我不希望宏将其删除,因为这会删除批量值 – 2015-04-02 14:55:34
因此,无论是在开始处还是在后面加上一个空格(或标点符号?),或者在空格前面和末尾(或只有标点符号)?不过呢,说'The'和'The Ltd.'。 – pnuts 2015-04-02 15:06:36