Excel 如何删除具有特殊符号的单元格的行?
我需要删除包含®的单元格的行Excel 如何删除具有特殊符号的单元格的行?,excel,vba,Excel,Vba,我需要删除包含®的单元格的行 Cells(iCntr, 6).Value = "*®*" Cells(iCntr, 6).Value = "®" 我也尝试过设置条件范围和条件,但我没有能够得到任何关于特殊角色的工作 Sub Remove() Dim lRow As Long Dim iCntr As Long lRow = 1000 For iCntr = lRow To 1 Step -1 If Cells(iCntr, 6).Value = "BLK" Then
Cells(iCntr, 6).Value = "*®*"
Cells(iCntr, 6).Value = "®"
我也尝试过设置条件范围和条件,但我没有能够得到任何关于特殊角色的工作
Sub Remove()
Dim lRow As Long
Dim iCntr As Long
lRow = 1000
For iCntr = lRow To 1 Step -1
If Cells(iCntr, 6).Value = "BLK" Then
Rows(iCntr).Delete
ElseIf Cells(iCntr, 6).Value = "WHI" Then
Rows(iCntr).Delete
ElseIf Cells(iCntr, 7).Value = "*®*" Then
Rows(iCntr).Delete
End If
Next
End Sub
代码对“BLK”和“WHI”的效果很好,但使用“®”时不会取出任何内容。没有错误消息,它只是不修改工作表。您可以像使用
一样使用:
ElseIf Cells(iCntr, 7).Value Like "*®*" Then
这个问题可以转化为“如何检查字符串是否包含特定的子字符串”,因为一旦解决了这个部分,相应的单元格就可以被删除
是一个函数,它比较两个字符串,返回第一个字符串中第二个字符串的位置。如果在第一个中未找到第二个,则返回0
。对于一些幻想,这可以用来查看(R)是否存在:
Sub TestMe()
Debug.Print ThePresenceOfR("kt®b")
Debug.Print ThePresenceOfR("tzv")
End Sub
Function ThePresenceOfR(str As String) As Boolean
ThePresenceOfR = InStr(1, str, "®")
End Function
或者如中所述,kt®;b如“*”
将提供相同的结果