如何添加到此VBA代码中,以便仅复制值和格式
Private Sub GENERATE_OP_SHEET_Click()
Dim i As Byte
For i = 1 To 1
Sheets("TEMPLATE").Copy After:=Sheets("TEMPLATE")
Set Sh = ActiveSheet
ActiveSheet.Name = Range("g2").Text
Next i
End Sub
答案 0 :(得分:0)
您可以尝试以下方法:
Private Sub GENERATE_OP_SHEET_Click()
Sheets("TEMPLATE").Copy After:=Sheets("TEMPLATE")
With ActiveSheet ' after 'Copy' statemement the copied sheet is the "active" one
.Name = Range("g2").Text
.UsedRange.Value = .UsedRange.Value ' leave values only
End With
End Sub
答案 1 :(得分:0)
根据我的测试,请尝试以下代码:
Private Sub GENERATE_OP_SHEET_Click()
Sheets("TEMPLATE").Copy After:=Sheets("TEMPLATE")
ActiveSheet.Name = Range("g2").Text
With Sheets("TEMPLATE").UsedRange
.Value = .Value 'converts formulas to values
End With
End Sub
有关更多信息,请参见:
Copy Excel sheet to another excel book but just formats and values