vbanovice1
New Member
- Joined
- Apr 22, 2024
- Messages
- 4
- Office Version
- 365
- Platform
- Windows
Hi all
I've been looking for threads that could help but haven't found any that I've been able to use.
My problem is that I have a workbook with multiple sheets, each sheet has formulas to get info from 2 other sheets in the workbook.
I need to copy each sheet (except for the two with the info) separately to another workbook, paste values and formatting, lock all cells except for a small range and then save each workbook to a specific place with the values in cells B2 and B4 as the name of the new workbook.
I have this code but I always get #Value in the cells that have formulas in them, not the values. Can anyone help me with this problem?
Sub CopyWorksheets()
Dim ws As Worksheet
MyPath = "the path to the folder I've chosen"
For Each ws In ThisWorkbook.Worksheets
If ws.Name = "Reiknireglur" Or "Ýmislegt" Then
Else
ws.Copy
Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveSheet.Protect Password:="Password"
ActiveWorkbook.SaveAs FileName:=MyPath & "\" & Range("B2") & " " & Range("B4") & " - " & "vor 2024" & ".xlsx"
ActiveWorkbook.Close savechanges:=False
End If
Next ws
End Sub
I've been looking for threads that could help but haven't found any that I've been able to use.
My problem is that I have a workbook with multiple sheets, each sheet has formulas to get info from 2 other sheets in the workbook.
I need to copy each sheet (except for the two with the info) separately to another workbook, paste values and formatting, lock all cells except for a small range and then save each workbook to a specific place with the values in cells B2 and B4 as the name of the new workbook.
I have this code but I always get #Value in the cells that have formulas in them, not the values. Can anyone help me with this problem?
Sub CopyWorksheets()
Dim ws As Worksheet
MyPath = "the path to the folder I've chosen"
For Each ws In ThisWorkbook.Worksheets
If ws.Name = "Reiknireglur" Or "Ýmislegt" Then
Else
ws.Copy
Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveSheet.Protect Password:="Password"
ActiveWorkbook.SaveAs FileName:=MyPath & "\" & Range("B2") & " " & Range("B4") & " - " & "vor 2024" & ".xlsx"
ActiveWorkbook.Close savechanges:=False
End If
Next ws
End Sub