我在每个单元格中都有一列文字,字符串null
位于其中许多字段的末尾。我想解析列中的每个单元格,如果单元格的内容以该字符串结尾,则从该单元格中删除只需null
。如何匹配字符串末尾的子字符串,然后只删除该子字符串?
我写什么,到目前为止去除成功结束null
如果它和前面的单词之间的空间,但如果有前一个字和null
之间没有空格删除整个细胞的内容。
Sub TruncateNulls()
Dim strPattern As String: strPattern = "\w*null\b"
Dim strReplace As String: strReplace = ""
Dim regEx As New RegExp
Dim strInput As String
ActiveSheet.Range("A2").Select
Do While ActiveCell.Value <> ""
strInput = ActiveCell.Value
With regEx
.Global = False
.MultiLine = True
.IgnoreCase = True
.Pattern = strPattern
End With
If regEx.Test(strInput) Then
ActiveCell = regEx.Replace(strInput, strReplace)
End If
ActiveCell.Offset(1, 0).Select
Loop
End Sub
实施例的输入数据:
words
null
wordsnull
words null
nullwords
希望的输出数据:
words
words
words
nullwords
如何调整此仅删除结束null
,不论前面的字符?
或者,我愿意使用搜索& Excel的Find
功能,或特定的通配符/通配符的组合替换窗口,如果任这些选项的作用。
'如果strInput喜欢“* null”那么' –