简体   繁体   中英

Copy sheets with udf to a new workbook

I have a workbook with 5 sheets full of UDF (user defined functions).
I need to copy these 5 sheets to a new workbook but I only need the values.
The problem is that when I copy these sheets all cells with UDF became broken with #value on it, because I don't have my macros on this new workbook.

I cannot copy the module, because many users will use this workbook and maybe their Excel will not allow me to manipulate the vba project .

I tried copying and pasting only values between workbook but it doesn't work. I think that is because my sheet have a lot of merged rows and columns. Excel shows an error message. I'll translate from portuguese to english here, maybe Excel doesn't use this exactly workd:

This option requires that merged cells are all the same size.

I don't understand this error. I even tried to do this manually: copy the entire sheet (right click, move and copy), then selected all the used range on my original workbook, ctrl+c, then selected the first cell in the new workbook then ctrl+v and then paste only values. And Excel throws an error. I also tried selecting the entire range on the new workbook before pressing ctrl+v. Same problem.

I don't know what to do. What I am doing now is copying and pasting only values in my original workbook and then copying the entire sheet to a new workbook. The problem is that this action destroy my original workbook, so I have to close it and reopen, what I didn't want to do.

Anyone have any idea on how to proceed?

Try these steps

  1. Copy the sheets inside the existing file.
  2. Copy then paste values all info in the newly copied sheet (in the existing file)
  3. Move the newly copied (and newly pasted values) sheet to a new file.

Given you asked for code, you can automate guitarthrower's solution as below (where you would change your sheet names in the book to be copied below)

Sub Redone()
Dim WB As Workbook
Dim ws As Worksheet

'runs on ActiveWorkbook
Set WB = ActiveWorkbook
WB.Sheets(Array("Sheet1", "Sheet2", "Sheet3", "Sheet4", "Sheet5")).Copy

'converts formulae to values on new workbook with the 5 specific sheets
For Each ws In ActiveWorkbook.Sheets
    ws.UsedRange.Value = ws.UsedRange.Value
Next

End Sub

Try this:

  • Copy the complete file using SaveAs
  • In the copy of the file go to each of the target sheets.
  • Right-click the top left cell and select copy:

在此输入图像描述

  • Then right-click again and select paste special choosing values only.
  • Now delete all the sheets that you do not want included.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM