求个可替换EXCEL分页中指定内容的宏,高手来帮帮忙!!
EXCEL表中有几百个分页,每个分页的不固定的某行上有个“(误报)”这四个字符需要替换为空或删除,该内容其中百分之70是在第一列,另一部分是第一列与第N列的合并单元格。手...
EXCEL表中有几百个分页,每个分页的不固定的某行上有个“(误报)”这四个字符需要替换为空或删除,该内容其中百分之70是在第一列,另一部分是第一列与第N列的合并单元格。手动一个个删太累了,求高手能写个宏不?最好运行完后可以显示成功替换了多少个分页就更好了,呵呵。
展开
2个回答
展开全部
'我写的宏,在sheet表名上右键,选 查看代码,将下面的代码复制入其中,按F5运行
'-------------------
Public Sub 替换()
'在所有sheet内,替换数据,并列出每个sheet的替换数量
Dim iStr As String: iStr = "(误报)" '要删除的字符,可更改,""内的内容
Dim iRep As String: iRep = "" '用于替换的字符,放入""内(留空为删除)
Dim n() As Integer
Dim nSht As Integer: nSht = ActiveWorkbook.Worksheets.Count
ReDim n(1 To nSht)
Dim iFind As Range
Dim Add1 As String
Dim iBool As Boolean
Dim iMsg As String: iMsg = ""
For i = 1 To nSht
n(i) = 0
With Worksheets(i).UsedRange
Set iFind = .Find(iStr, LookIn:=xlValues, Lookat:=xlWhole)
If Not iFind Is Nothing Then
Add1 = iFind.Address
Do
n(i) = n(i) + 1
iFind.Value = iRep
Set iFind = .FindNext(iFind)
If iFind Is Nothing Then Exit Do
Loop While iFind.Address <> Add1
End If
End With
If n(i) <> 0 Then iMsg = iMsg & vbCrLf & "在表 " & Worksheets(i).Name & " 内,更改 " & n(i) & " 处"
Next
If iMsg <> "" Then
MsgBox iMsg
Else
MsgBox "一个都没找到!" & vbCrLf & "请检查查找条件是否正确。", 48
End If
End Sub
'--------------------
'其他问题,Hi我
'-------------------
Public Sub 替换()
'在所有sheet内,替换数据,并列出每个sheet的替换数量
Dim iStr As String: iStr = "(误报)" '要删除的字符,可更改,""内的内容
Dim iRep As String: iRep = "" '用于替换的字符,放入""内(留空为删除)
Dim n() As Integer
Dim nSht As Integer: nSht = ActiveWorkbook.Worksheets.Count
ReDim n(1 To nSht)
Dim iFind As Range
Dim Add1 As String
Dim iBool As Boolean
Dim iMsg As String: iMsg = ""
For i = 1 To nSht
n(i) = 0
With Worksheets(i).UsedRange
Set iFind = .Find(iStr, LookIn:=xlValues, Lookat:=xlWhole)
If Not iFind Is Nothing Then
Add1 = iFind.Address
Do
n(i) = n(i) + 1
iFind.Value = iRep
Set iFind = .FindNext(iFind)
If iFind Is Nothing Then Exit Do
Loop While iFind.Address <> Add1
End If
End With
If n(i) <> 0 Then iMsg = iMsg & vbCrLf & "在表 " & Worksheets(i).Name & " 内,更改 " & n(i) & " 处"
Next
If iMsg <> "" Then
MsgBox iMsg
Else
MsgBox "一个都没找到!" & vbCrLf & "请检查查找条件是否正确。", 48
End If
End Sub
'--------------------
'其他问题,Hi我
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询