• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Copy and paste between 2 different files,located in different place

copy data from this location C:\Users\user\Desktop\Stock Market\Sholtan\1.xlsm
paste data to this location C:\Users\user\Desktop\Stock Market\Sholtan\Night.xlsb
macro will be placed in Night.xlsb
we have to copy complete sheet of sheet name= 1 from 1.xlsm
we have to paste that data in sheet name = Sheet1 in Night.xlsb
 
Leonardo1234
Code:
Workbooks(from_file).Sheets("1").UsedRange.Copy Destination:=Workbooks(to_file).Sheets("Sheet1").Range("A1")

Of course, there would be many 'if'-cases ...
 
Code:
Sub test()
Workbooks(from_file).Sheets("1").UsedRange.CopyDestination:=Workbooks(to_file).Sheets("Sheet1").Range("A1")
End Sub
This way i have to right this vba code am i right vletm Sir?
 
Leonardo1234
As You wrote
copy data from this location C:\Users\user\Desktop\Stock Market\Sholtan\1.xlsm
paste data to this location C:\Users\user\Desktop\Stock Market\Sholtan\Night.xlsb

from_file is Your copy data from this location and
to_file is Your paste data to this location.
Okay?
 
vletm sir plz provide me a complete macro code
i can't make the code from the details u have given plz provide me a complete macro (code)
 
This is what vletm means
Code:
Sub vletm()
Workbooks("C:\Users\user\Desktop\Stock Market\Sholtan\1.xlsm ").Sheets("1").UsedRange.Copy _
Destination:=Workbooks("C:\Users\user\Desktop\Stock Market\Sholtan\Night.xlsb").Sheets("Sheet1").Range("A1")
End Sub
 
Dear All,

Sorry for hacke this thread...but just to learning purpose.

Is it can be offline process?
Code reside in any file or newly created blank file?
Or both file closed & run from (through) macro in personnel.xlsb?
Is source file opened and targeted file closed?
Both workbooks must be opened when run this process ?
What happen when target file already have some data on it? How can make dynamic?
Can be more possibility?

Regards,

Chirag Raval
 
Chirag R Raval
What would You mean about 'offline process'?
Both files have to be created and open.
#5 Reply can use with those variables.
This would overwrite to target file.
'dynamic' ... before 'paste' gotta find next empty row or if 'paste' over then gotta find that range.
Many things are possible ... gotta know what would like to happen.
This case was from file to other file ...
Why all Your macros should be in personnel.xlsb?
 
Leonardo1234
That same macro with those settings can run only if have those files in those folders.
What error it gives?
Are Your path and filenames as written?
 
The given code will be placed in Night file and we have to open file 1 then we have to copy the data from 1 file and then paste it to Night file and then close 1 file
All this i have to do by vba
 
Leonardo1234
There were few questions ...
Previous code has one extra space, one reason for something.
Next sample code worked here after You will copy it to correct place.
I didn't add any error checks ....
Code:
Sub Do_It()
    from_file = "C:\Users\user\Desktop\Stock Market\Sholtan\1.xlsm"
    to_file = ThisWorkbook.Name
    Workbooks.Open from_file
    Workbooks(from_file).Sheets("1").UsedRange.Copy _
        Destination:=Workbooks(to_file).Sheets("Sheet1").Range("A1")[/SIZE]
    Workbooks(from_file).Close savechanges = False
End Sub
 
Leonardo1234
I've run that before and again ... of course with my settings and files.
( = I do not have those paths nor files here! )
... and I didn't get ANY errors!

Where did You copy that code?
a) Send screenshot from that error here.
b) Send screenshot from You code.
c) Send those files here
 
Leonardo1234
I see .. that You haven't done so much VBA ...
There were left for some mystery reason few extra marks ... and so on.
>> code is in Sheet1 code
 

Attachments

  • Night.xlsb
    30.1 KB · Views: 3
Always try to write WHERE
Sometimes, it's challenge to find where is cannot use same settings ...
 

Attachments

  • Night.xlsb
    33.3 KB · Views: 3
Back
Top