Copy sheet with cube formulas to new book results in #NAME?

semmio

New Member
Joined
Aug 24, 2017
Messages
3
Hi!
all my previous question I found answers on on this forum, but on the following question I couldn't find any related topics:

I'm trying to write a VBA code to copy paste 2 sheets of my workbook to a new book. So far no problem with VBA code below:

Code:
Sub Button1_Click()
    With ThisWorkbook
    .Worksheets("budget 1").Unprotect
        .Worksheets("budget 1").Copy
        ActiveSheet.Cells.Copy
        ActiveSheet.Range("A1").PasteSpecial Paste:=xlPasteValues
        .Worksheets("budget 2").Unprotect
        .Worksheets("budget 2").Copy After:=ActiveWorkbook.Worksheets(ActiveWorkbook.Worksheets.Count)
        ActiveSheet.Cells.Copy
        ActiveSheet.Range("A1").PasteSpecial Paste:=xlPasteValues
        .Worksheets("budget 2").Protect
        .Worksheets("budget 1").Protect
    End With
    Application.CutCopyMode = False
End Sub

BUT...
all the CUBEVALUE and CUBEMEMBER formulas in the original workbook result as #NAME ? instead of the values in the new book.

Anyone an idea how to copy paste the sheet values and keep original layout and formats like hidden columns, conditional formatting etcetera?

Thanks a lot!
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
UPDATE:

when I copy paste within the same workbook, the values of the cubevalue formula DO appear.

I don't exactly know what I'm doing in the VBA code, but this code below does the right thing, except from pasting the sheets to a new book.

Code:
Sub Button1_Click()
    With ThisWorkbook
    .Worksheets("budget 1").Unprotect
        .Worksheets("budget 1").Copy After:=ActiveWorkbook.Worksheets(ActiveWorkbook.Worksheets.Count)
        ActiveSheet.Cells.Copy
        ActiveSheet.Range("A1").PasteSpecial Paste:=xlPasteValues
        .Worksheets("budget 2").Unprotect
        .Worksheets("budget 2").Copy After:=ActiveWorkbook.Worksheets(ActiveWorkbook.Worksheets.Count)
        ActiveSheet.Cells.Copy
        ActiveSheet.Range("A1").PasteSpecial Paste:=xlPasteValues
        .Worksheets("budget 2").Protect
        .Worksheets("budget 1").Protect
    End With
    Application.CutCopyMode = False
End Sub
 
Upvote 0
UPDATE: SOLVED

Below code first copies the sheets, then moves the new sheets to a new book. And that seems to work. I had to delete the button in the copied sheet though, otherwise it would error.


Code:
Sub Button1_Click()
    With ThisWorkbook
    .Worksheets("budget 1").Unprotect
    Application.CopyObjectsWithCells = False 
        .Worksheets("budget 1").Copy After:=ActiveWorkbook.Worksheets(ActiveWorkbook.Worksheets.Count)
        ActiveSheet.Cells.Copy
        ActiveSheet.Range("A1").PasteSpecial Paste:=xlPasteValues
        Application.CopyObjectsWithCells = False
        ActiveSheet.Name = "budget 1 copy"
        
        .Worksheets("budget 2").Unprotect
        .Worksheets("budget 2").Copy After:=ActiveWorkbook.Worksheets(ActiveWorkbook.Worksheets.Count)
        ActiveSheet.Cells.Copy
        ActiveSheet.Range("A1").PasteSpecial Paste:=xlPasteValues
        ActiveSheet.Name = "budget 2 copy"
        
   
        .Worksheets("budget 1").Protect
         .Worksheets("budget 2").Protect
         
      
      .Worksheets("budget 1 copy").Move
      .Worksheets("budget 2 copy").Move After:=ActiveWorkbook.Worksheets(ActiveWorkbook.Worksheets.Count)
    
                
             
    End With
   
End Sub



Feels like a workaround, so if someone has a more simple solution, please let me know!
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top