|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 数据替换3()
Dim I As Long, J As Long
Dim NewName As String
Dim Cz As String
Dim wb As Workbook
Dim nowWbName As String
For Each wb In Application.Workbooks
'在当前打开的工作簿中循环
If wb.Name <> ThisWorkbook.Name Then
'删除工作表名称中的空格
For I = 1 To wb.Sheets.Count
' 按照工作簿中工作表的数量进行循环
wb.Sheets(I).Name = Trim(Replace(wb.Sheets(I).Name, " ", ""))
kk = wb.Sheets(I).Name
Next
For I = 1 To wb.Sheets.Count
' 按照工作簿中工作表的数量进行循环
Cz = "否"
If InStr(wb.Sheets(I).Name, "(2)") > 0 Then
' 如果工作表名称中含有“(2)”
NewName = Trim(Replace(wb.Sheets(I).Name, "(2)", ""))
For J = 1 To wb.Sheets.Count
If wb.Sheets(J).Name = NewName Then
' 如果NewName这个工作表存在
wb.Sheets(NewName).Activate
Range("A1").CurrentRegion.Select
Selection.Clear
wb.Sheets(I).Activate
Range("A1").CurrentRegion.Select
Selection.Copy
wb.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
End If
Next wb
MsgBox "OK!"
End Sub |
评分
-
1
查看全部评分
-
|