VBA Question (Copy and Paste)

Tfox2791

New Member
Joined
Nov 21, 2012
Messages
32
I would like to only copy the values and the formating to the new workbook and worksheet. My code currently copies everything and all of the formulas so when the new workbooks are emailed out they show errors because the link is broken. I tried a few different methods but have been unsucessful, any thoughts?

Thanks for your sugesstions and help in advance....

Current Code:
Dim wbThis As Workbook
Dim wbNew As Workbook
Dim ws As Worksheet
Dim strFileName As String
Dim path As String
Dim name As String

Application.ScreenUpdating = False
path = "G:\Student Services\"
Set wbThis = ActiveWorkbook


For Each ws In wbThis.Worksheets

strFileName = "Drop Analysis " & ws.Cells(1, 105).Text & ".xlsx"
name = ws.Cells(1, 105)
If Dir(name) <> "" Then GoTo Blank

ws.Copy

Application.DisplayAlerts = False

Set wbNew = ActiveWorkbook

wbNew.SaveAs Filename:=(path & strFileName)

wbNew.Close
Blank:
Next ws

End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

wigi

Well-known Member
Joined
Jul 10, 2006
Messages
7,964
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
Hi

Did you try PasteSpecial? For example:

Code:
Sub wigi()
    Range("A1").Copy
    Range("A2").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
End Sub
 
Upvote 0

madaknarf

New Member
Joined
Sep 5, 2014
Messages
13
you can try adding this to your code after you copy the worksheet. The idea is that if the numbers on the copied worksheet are good before you save this will copy and paste special all the values on the sheet before you save as.

Cells.Select
Cells.PasteSpecial xlPasteValuesAndNumberFormats
 
Upvote 0

Tfox2791

New Member
Joined
Nov 21, 2012
Messages
32
I tried the paste special route but it doesnt seem to work? I tried to insert ws.PasteSpecial xlPasteValuesAndNumberFormats after Set wbNew = ActiveWorkbook and it give me an error (Method of Paste Special Object _ Worksheet Failed)?
 
Upvote 0

wigi

Well-known Member
Joined
Jul 10, 2006
Messages
7,964
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
Tfox2791;3929634I tried to insert ws.PasteSpecial xlPasteValuesAndNumberFormats and it give me an error (Method of Paste Special Object _ Worksheet Failed)?[/QUOTE said:
Yes it does, since I showed you in my example that PasteSpecial applies to a range like Range("A2") instead of to a worksheet like ws.
 
Upvote 0

Forum statistics

Threads
1,191,377
Messages
5,986,277
Members
440,016
Latest member
vasanrajeswaran

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
Top