DavyJones90
Board Regular
- Joined
- Feb 23, 2022
- Messages
- 62
- Office Version
- 365
- Platform
- Windows
Hey there,
I don't get exactly what I need to change to make this code work. I need two worksheets to be copied to a new workbook and pasted as values. This is my code.
With the second Worksheet, I get the "out of range" error
Thanks in advance,
David
I don't get exactly what I need to change to make this code work. I need two worksheets to be copied to a new workbook and pasted as values. This is my code.
VBA Code:
Public Sub Modelo()
Dim newWorkbook As Workbook
Dim newWbPath As String: newWbPath = ThisWorkbook.Path & "\MODELOMNI DATA.xlsx"
Set newWorkbook = Workbooks.Add
ThisWorkbook.Worksheets("AUTO ENTRY POINTS").Range("O4").NumberFormat = "dd/mm/yy"
ThisWorkbook.Worksheets("AUTO ENTRY POINTS").Range("O4").Value = Date
ThisWorkbook.Worksheets("AUTO ENTRY POINTS").Cells.Copy
newWorkbook.Worksheets(1).Cells.PasteSpecial Paste:=xlPasteFormats
newWorkbook.Worksheets(1).Cells.PasteSpecial Paste:=xlPasteValuesAndNumberFormats
newWorkbook.Worksheets(1).Range("A:A").ClearContents
newWorkbook.Worksheets(1).Name = "Values"
ThisWorkbook.Worksheets("XL FILE").Cells.Copy
newWorkbook.Worksheets(2).Cells.PasteSpecial Paste:=xlPasteFormats
newWorkbook.Worksheets(2).Cells.PasteSpecial Paste:=xlPasteValuesAndNumberFormats
newWorkbook.Worksheets(2).Name = "XL FILE"
Application.CutCopyMode = False
newWorkbook.SaveAs newWbPath
newWorkbook.Close
End Sub
With the second Worksheet, I get the "out of range" error
Thanks in advance,
David