PDA

View Full Version : VBA to save as not saving values.



MattehWoo
09-30-2016, 02:25 AM
Hi all,

I have the following code which copies and saves selected worksheets into a new workbook. However it is not copying the values from the formulas and just brings them all over as '#N/A'.

Where am i going wrong?


Option Explicit
Sub Save()
Dim NewName As String
Dim nm As Name
Dim ws As Worksheet

If MsgBox("Save Data?" & vbCr & _
"This will close the tool." _
, vbYesNo, "NewCopy") = vbNo Then Exit Sub

With Application
.ScreenUpdating = False

On Error GoTo ErrCatcher
Sheets(Array("Numbers", "Graph")).Copy
On Error GoTo 0

For Each ws In ActiveWorkbook.Worksheets
ws.Cells.Copy
ws.[A1].PasteSpecial Paste:=xlValues
ws.Cells.Hyperlinks.Delete
Application.CutCopyMode = False
Cells(1, 1).Select
ws.Activate
Next ws
Cells(1, 1).Select

For Each nm In ActiveWorkbook.Names
nm.Delete
Next nm

Application.Dialogs(xlDialogSaveAs).Show

.ScreenUpdating = True
End With


Workbooks("Main Book").Close savechanges:=False


Exit Sub




End Sub

Kenneth Hobs
09-30-2016, 05:00 AM
'ws.Cells.Copy
' ws.[A1].PasteSpecial Paste:=xlValues
[/COLOR]ws.cells.value = ws.cells.value

MattehWoo
10-04-2016, 03:31 AM
Hmm trying this and i'm getting an out of memory error?

Kenneth Hobs
10-04-2016, 04:45 AM
Try:

ActiveSheet.UsedRange.Value = ActiveSheet.UsedRange.Value

MattehWoo
10-04-2016, 06:24 AM
It now does part of the job :)

But it's still showing an error "#NAME?" where the formula brought back the numbers.

Kenneth Hobs
10-04-2016, 08:21 AM
It is hard to guess what is going on. Can you make a simple file and attach it? Attach by clicking the Go Advanced button and then the paperclip icon.

MattehWoo
10-05-2016, 02:18 AM
17264

Kenneth Hobs
10-05-2016, 04:41 AM
Since the UDF MattUsageCode() does not exist, you get the ?Name$ error.

MattehWoo
10-05-2016, 05:12 AM
Hmm. If i made the code copy over the formula with values before doing this part, it should work?

Kenneth Hobs
10-05-2016, 08:56 AM
Yes, that was what I was showing you how to do. Was that not the point of post #1?

MattehWoo
10-06-2016, 01:20 AM
I obviously confused myself. But it's all working now!

Many thanks for your help Mr Hobs!