|
楼主 |
发表于 2023-2-13 15:40
|
显示全部楼层
Sub CopyActiveSheetAndRename()
Dim xStr As String
Dim newSheet As Worksheet
Dim dateStr As String
dateStr = InputBox("请输入工作表的日期(格式为月.日):", "输入日期")
If dateStr = "" Then
Exit Sub
End If
Set newSheet = ActiveSheet.Copy(After:=Sheets(Sheets.Count))
Retry:
Err.Clear
xStr = InputBox("请输入工作表的新名称(格式为月.日):" _
, "重命名工作表", dateStr)
If xStr = "" Then
Exit Sub
Sub demo()
Set sht = ActiveSheet
ActiveSheet.Copy After:=Sheets(Sheets.Count)
Set newsht = ActiveSheet
Dim xStr As String
Retry:
Err.Clear
xStr = InputBox("请输入工作表的新名称:" _
, "重命名工作表", ActiveSheet.Name)
If xStr = "" Then Exit Sub
On Error Resume Next
ActiveSheet = xStr
If Err.Number <> 0 Then
MsgBox Err.Number & " " & Err.Description
Err.Clear
GoTo Retry
End If
On Error GoTo 0
Range("B5:B10,B12:B21,B24").ClearContents
newsht.[c5].Formula = "=" & sht.Name & "'!C5+B5"
End Sub
这两个吗 咋改呢
End If
On Error Resume Next
newSheet.Name = xStr
If Err.Number <> 0 Then
MsgBox Err.Number & " " & Err.Description
Err.Clear
GoTo Retry
End If
On Error GoTo 0
newSheet.Range("B5:B10,B12:B21,B24").ClearContents
newSheet.Range("C5").Value = _
Sheets(Replace(xStr, ".", ".") - 1).Range("C5").Value + newSheet.Range("B5").Value
newSheet.Range("B26").Value = Sheets(Replace(xStr, ".", ".") - 1).Range("B30").Value
newSheet.Range("B27").Value = Sheets(Replace(xStr, ".", ".") - 1).Range("B31").Value
End Sub
|
|