Hi all,
I am working to export a data set from one workbook, with the new workbook being macro-free. I then need to replace the formula references in the new Workbook to remove the old workbook. I have cobbled together coding from various sources, but cannot get the replace part of the coding to work.
Any help is super appreciated.
I am working to export a data set from one workbook, with the new workbook being macro-free. I then need to replace the formula references in the new Workbook to remove the old workbook. I have cobbled together coding from various sources, but cannot get the replace part of the coding to work.
Any help is super appreciated.
VBA Code:
Public Sub ExportNewBook()
Dim newWb As Workbook
sname = ActiveWorkbook.Worksheets("Summary").Range("B1") & ".xlsx"
Dim newWbPath As String: newWbPath = ThisWorkbook.Path & "\" & sname
Dim FindMe As String, Replacement As String
FindMe = "[2025_ONA_Monthly_Schedule_randomizer - Test 2.xlsm]"
Replacement = ""
Application.SheetsInNewWorkbook = 8
Set newWb = Workbooks.Add
ThisWorkbook.Worksheets("Summary").Cells.Copy
newWb.Worksheets(1).Cells.PasteSpecial Paste:=xlPasteFormulas
newWb.Worksheets(1).Cells.PasteSpecial Paste:=xlPasteFormats
Application.CutCopyMode = False
newWb.Worksheets("Sheet1").Name = "Summary"
ThisWorkbook.Worksheets("Adult Assignment").Cells.Copy
newWb.Worksheets(2).Cells.PasteSpecial Paste:=xlPasteValues
newWb.Worksheets(2).Cells.PasteSpecial Paste:=xlPasteFormats
Application.CutCopyMode = False
newWb.Worksheets("Sheet2").Name = "Adult Assignment"
ThisWorkbook.Worksheets("Youth Assignment").Cells.Copy
newWb.Worksheets(3).Cells.PasteSpecial Paste:=xlPasteValues
newWb.Worksheets(3).Cells.PasteSpecial Paste:=xlPasteFormats
Application.CutCopyMode = False
newWb.Worksheets("Sheet3").Name = "Youth Assignment"
ThisWorkbook.Worksheets("SCONAs").Cells.Copy
newWb.Worksheets(4).Cells.PasteSpecial Paste:=xlPasteValues
newWb.Worksheets(4).Cells.PasteSpecial Paste:=xlPasteFormats
Application.CutCopyMode = False
newWb.Worksheets("Sheet4").Name = "SCONAs"
ThisWorkbook.Worksheets("SCONAY").Cells.Copy
newWb.Worksheets(5).Cells.PasteSpecial Paste:=xlPasteValues
newWb.Worksheets(5).Cells.PasteSpecial Paste:=xlPasteFormats
Application.CutCopyMode = False
newWb.Worksheets("Sheet5").Name = "SCONAY"
ThisWorkbook.Worksheets("BA ONAs").Cells.Copy
newWb.Worksheets(6).Cells.PasteSpecial Paste:=xlPasteValues
newWb.Worksheets(6).Cells.PasteSpecial Paste:=xlPasteFormats
Application.CutCopyMode = False
newWb.Worksheets("Sheet6").Name = "BA ONAs"
ThisWorkbook.Worksheets("BY ONAS").Cells.Copy
newWb.Worksheets(7).Cells.PasteSpecial Paste:=xlPasteValues
newWb.Worksheets(7).Cells.PasteSpecial Paste:=xlPasteFormats
Application.CutCopyMode = False
newWb.Worksheets("Sheet7").Name = "BY ONAS"
ThisWorkbook.Worksheets("CIIS").Cells.Copy
newWb.Worksheets(8).Cells.PasteSpecial Paste:=xlPasteValues
newWb.Worksheets(8).Cells.PasteSpecial Paste:=xlPasteFormats
Application.CutCopyMode = False
newWb.Worksheets("Sheet8").Name = "CIIS"
'This is where this issue is at - can't get this part to work
newWb.Sheets("Summary").Activate
Columns("B:w").Replace FindMe, Replacement, xlWhole, , True, , False, False
newWb.SaveAs newWbPath
End Sub