|
Sub 数据替换3()
Dim I As Long, J As Long
Dim NewName As String
Dim Cz As String
'删除工作表名称中的空格
For I = 1 To ThisWorkbook.Sheets.Count
' 按照工作簿中工作表的数量进行循环
Sheets(I).Name = Trim(Replace(Sheets(I).Name, " ", ""))
Next
For I = 1 To ThisWorkbook.Sheets.Count
' 按照工作簿中工作表的数量进行循环
Cz = "否"
If InStr(Sheets(I).Name, "(2)") > 0 Then
' 如果工作表名称中含有“(2)”
NewName = Trim(Replace(Sheets(I).Name, "(2)", ""))
For J = 1 To ThisWorkbook.Sheets.Count
If Sheets(J).Name = NewName Then
' 如果NewName这个工作表存在
Sheets(NewName).Activate
Range("A1").CurrentRegion.Select
Selection.Clear
Sheets(I).Activate
Range("A1").CurrentRegion.Select
Selection.Copy
Sheets(NewName).Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlPasteSpecialOperationNone, SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlPasteSpecialOperationNone, SkipBlanks:=False, Transpose:=False
Cz = "是"
End If
Next
If Cz <> "是" Then
MsgBox "工作簿中不存在名称为 " & NewName & " 的工作表,请检查。"
End
End If
End If
Next
MsgBox "OK!"
End Sub
改了一下,去掉了那个函数。 |
|