Automating tedious copy & pasting

Jokes

New Member
Joined
Aug 18, 2012
Messages
17
I was wondering if there was anyway to automate this process. Say take all the files in this folder copy visible cells on a specific tab and paste them into a new worksheet/model we already have built. They shouldn't be consolidated rather pasted below the next. Anyway to do this?
 
Yes it can be done in VB.
Do you have much experience in VB?
Is the location of the new worksheet in the same location as the files you're copying?
 
Upvote 0
I have limited experience in VB but do understand it somewhat. I started recording macros and recently starting adding to macros by using code, adding more steps, and changing the tab name/where the info was to be pasted etc. But have yet to write code from scratch. Location doesn't matter to me, I was thinking I create a new folder let's name it "X" the new worksheet I would imagine would not be in that folder, but just one level up. Lets call that "Y". I want to take tab "Z" of every file in folder "X" and put them all successively in the new file "Y". Location can change depending on how we need it. Would you happen to be able to come up with some code I could work with? Also need to paste special values on visible cells on said files. Help would e greatly appreciated. Thanks!
 
Upvote 0
I'll work on something this weekend, unless someone else provides the answer sooner. :) Have a good weekend Jokes.
 
Upvote 0
I've tested this, and it works on my system, see how you go on yours. You will need to adjust the MAIN file name, or the file name of where you're pasting, and the directory of where you are capturing all of the files.

Sub autocopy()
Dim filesystem As Object, myfolder As Object
Dim myfiles As Object, myfile As Object, Pastefile As Object
On Error Resume Next
Set filesystem = CreateObject("Scripting.filesystemobject")
Set myfolder = filesystem.getfolder("D:\LOCATION OF FILES YOU WANT TO OPEN")
Set myfiles = myfolder.Files
Set Pastefile = filesystem.getfile("D:\LOCATION\PASTEFILENAME.xlsx")
Workbooks.Open Filename:="D:\D:\LOCATION\PASTEFILENAME.xlsx"
For Each myfile In myfiles
Workbooks.Open Filename:=myfolder & "\" & myfile.Name
Workbooks(myfile.Name).Worksheets("Sheet1").Cells.Copy
Windows(Pastefile.Name).Activate
Worksheets.Add().Name = myfile.Name
ActiveSheet.Paste
Windows(myfile.Name).Activate
Application.CutCopyMode = False
ActiveWindow.Close
Next
End Sub
 
Upvote 0
Thank you so much! I do apologize for taking so long but do greatly appreciate your response. It's nice to know there are people out there willing to help. I think I got it from here, thanks again. Jokes
 
Upvote 0
I was in the hospital for a while and was unable to test this right now I am getting a syntax error on the very first part of this any ideas?
 
Upvote 0
Sorry got past that now it seems to run but nothing seems to happen feels like I am close but I am not sure how to fix it. It is now coming back with no errors but I do not see any results.
 
Upvote 0

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