我想创建一个宏给我一些问题,因为我没有经验,也不知道从哪里开始。Excel FInd并替换正则表达式宏
我所要做的就是创建一个查找并替换宏,它将用空白替换部分字符串。
例如,我有以下Custom Field(Id)
,我希望marco做的所有事情是从Id
中删除所有内容。
我该如何做到这一点?
代码
Sub FindReplace()
Dim sht As Worksheet
Dim fndList As Variant
Dim rplcList As Variant
Dim x As Long
fndList = Array("Custom field(", ")")
rplcList = Array("", "")
'Loop through each item in Array lists
For x = LBound(fndList) To UBound(fndList)
'Loop through each worksheet in ActiveWorkbook
For Each sht In ActiveWorkbook.Worksheets
sht.Cells.Replace What:=fndList(x), Replacement:=rplcList(x), _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
Next sht
Next x
End Sub
“Id”是一个数字吗? –
Nope Id是一个字符串,另一个例子是'Custom field(Status)',我只想保留'Status' – dataMan
,这样我的Solution1就可以用于这两种情况。你可以创建一个VBA代码,用于查找并替换字符串自定义字段(用于'nothing'和''查找并替换''char')用于'Nothing' –