[英]VBA Copy sheets to new workbook - with/without formulas
我使用此代碼將 4 張紙復制到單獨的工作簿中。 其中之一 - “1”里面有公式,下面的方法跳過這些公式。 任何想法如何保持三個工作簿的價值和一個 - “1”包括公式? 下面是負責該操作的部分代碼。 先感謝您。
Sub test()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Dim Fname As String, ws As Worksheet
Dim InitFileName As String, fileSaveName As String
Fname = Sheets("STRUCTURE").Range("A1").Value
Sheets(Array("STRUCTURE", "2", "3", "1")).Copy
For Each ws In ActiveWorkbook.Worksheets
With ws.UsedRange
.Value = .Value
End With
Next ws
With ActiveWorkbook
fileSaveName = "FILE LOCATION FOLDER " & Sheets("STRUCTURE").Cells(1, 1) & ".xlsx"
.SaveAs fileSaveName
.Close
End With
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
這就是將公式更改為值的原因:
With ws.UsedRange
.Value = .Value
End With
您有幾個選項可以跳過相關工作表:
1
的工作表。For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> "1" Then
With ws.UsedRange
.Value = .Value
End With
End If
Next
Dim sheetNamesToProcess As Variant
sheetNamesToProcess = Array("STRUCTURE", "2", "3")
Dim i As Long
For i = Lbound(sheetNamesToProcess) To Ubound(sheetNamesToProcess)
With ActiveWorkbook.Worksheets(sheetNamesToProcess(i)).UsedRange
.Value = .Value
End With
Next
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.