我在每個單元格中都有一列文字,字符串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」那麼' –