copy-paste from one Excel file to the other

Davorito

New Member
Joined
Nov 24, 2015
Messages
6
Hi guys,

The code I've been using doesn't give me the results I want.

Basically, I want it to copy-paste the two selections (which contains functions and graphs) to another Excel file (paste values and graphs). When it sends the data to the other file, I want it to create a new sheet based on a value in a cell.


Sub TransferData()
Dim x As Workbook
Dim y As Workbook
Dim ShtName As String


'## Open both workbooks first:
Set x = Workbooks.Open("C:\Davorito\Report generator.xlsm")
Set y = Workbooks.Open("C:\Davorito\Reports database.xlsm")

'name that will be used for a new sheet in the reports database
ShtName = Sheet1.Cells(1, 10).value

'checks if there are sheets with same name
If Not WksExists(ShtName) Then Worksheets.Add After:=Worksheets(Worksheets.Count)

ActiveSheet.Name = ShtName
'Now, copy what you want from x:
x.Sheets("Template").Range("A2:AC953").Copy


'Now, paste to y worksheet:
y.Sheets("sheetname").Range("A1").PasteSpecial
Selection.PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone _
, SkipBlanks:=False, transpose:=False
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, transpose:=False
'Now, copy what you want from x:
x.Sheets("Template").Range("A1021:AL1085").Copy


'Now, paste to y worksheet:
y.Sheets("sheetname").Range("A1").PasteSpecial
Selection.PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone _
, SkipBlanks:=False, transpose:=False
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, transpose:=False
'Close x:
x.Close


End Sub


Function WksExists(wksName As String) As Boolean
On Error Resume Next
WksExists = CBool(Len(Worksheets(wksName).Name) > 0)
End Function
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Forum statistics

Threads
1,214,613
Messages
6,120,515
Members
448,968
Latest member
Ajax40

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