I am trying to copy multiple worksheets to a new workbook. The worksheet names are defined in an array named sWorkSheetNames, which are then copied to a new workbook via swb.Worksheets(sWorkSheetNames).Copy.
The challenge I am facing is that the data on those worksheets is captured via complex indirect() formulas, which in turn pull data from a 100k+ long "DATA" worksheet. Now, via the above copy command, the indirect formulas break and throw a #REF error, which I can only circumvent by also copying the massive DATA sheet to the new workbook, then replace the formulas with values, and only then delete the DATA sheet, which is what I do not want to do.
My question now is this: how can I most effectively copy x number of sheets from the source workbook, replace the used range data to values, and then copy it to a new workbook, without knowing the worksheet name of the copied worksheets (copies in the same workbook are named "SomeName (x)" where x could be 1,2,3,4,etc depending on the number of copies)?
Thank you very much
Dim sWorkSheetNames() As Variant
sWorkSheetNames = Array("Daily Summary", "Monthly Summary")
' Reference the source workbook ('swb').
Dim swb As Workbook: Set swb = ThisWorkbook ' workbook containing this code
' Copy the worksheets to a new workbook.
swb.Worksheets(sWorkSheetNames).Copy
' Destination
' Reference this new workbook, the destination workbook ('dwb').
Dim dwb As Workbook: Set dwb = Workbooks(Workbooks.Count)
Dim dws As Worksheet
Dim drg As Range
' Convert formulas to values
' breaks the formulas since the indirect DATA sheet is not present in the new workbook
' copy paste to value needs to happen in the swb before copy
For Each dws In dwb.Worksheets
Set drg = dws.UsedRange
drg.Value = drg.Value
Next dws