VBA to open 2 workbooks(name changes on 1), copy and paste data and drag down existing formula

cdalgorta

Board Regular
Joined
Jun 5, 2022
Messages
87
Office Version
  1. 365
Platform
  1. Windows
Hi,
Thank you in advance. This one is a bit long. Sorry!

So I download a file daily and I use that to replace the data on another file which is 1 of my database excels for my main template.
The VBA that I'd need would be the following:
* Open both Excels(I'm guessing they have to be opened for this to work).
The daily new data always goes to my "Downloads" file, the name always starts with "Additional info looker Standard Unlimited " followed by the date and then random characters(I delete the one from the previous day, so there will always only be 1 file in my downloads that starts with "Additional info looker Standard Unlimited ".
There is only 1 sheet on the workbook and the name is always "Additional info looker Standard".
1658079371265.png


I need to copy all columns from A to S. The number of rows always changes(could be more, could be less), but it's between 100k to 200k(if that matters). Also, not sure if this matters as well, but A1 is empty as you can see in the image.
1658076462105.png


*By the way, this daily download file is a .csv file.*

Now, the file I need to paste the data in, is here:
C:\Users\cristian\Desktop\Standard Aging Local
Name: Additional Info Lookup Data
Sheet name: Additional Info Lookup
1658076750843.png

There are formulas on columns T and U, so I was thinking that the best way to do it, would be with a VBA that deletes everything below Row 3, paste the data from the previous file into this one from A2 to S2 all the way down, and then drag the formulas on T2 and U2 all the way down until the last row of the new data. And that would finish what I need.
1658077449548.png


P.S. If possible, I think a VBA that turns "Calculation Options" to "Manual" before opening the 2nd file with the formulas, and then another one that triggers "Calculate Now" after dragging down the formulas on T2 and U2, would make this better. For some reason, "sometimes" when I open the workbook with the formulas, it starts recalculating the formulas even though I just opened it and nothing has changed. I have to remind myself to click "manual" before I open any excel with formulas or I have to wait for the thing to finish calculating... 😞

P.P.S If possible as well, a VBA to close the 1st file at the very end would be great. I know the VBA to close a file with a fixed name, but not when the file name changes and only part of the name is fixed, "Additional info looker Standard Unlimited ".

Thank you so much in advance! I'm thinking of paying for a Coursera VBA course so that I can start helping others here as well instead of just asking for help. Hahaha. There are quiet a few, so any recommendations from the experts would be greatly appreciate it!

Cristian
 
So at the last yellow line pictured, post #37, You tapped the 'F8' key and then got the error correct?
 
Upvote 0

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Ok, so that means,
1) either the sheet name in the destination file is not named exactly as Additional Info Lookup
2) the previous couple of lines are not producing the desired result.

Is the sheet name in the destination file named exactly as Additional Info Lookup?
 
Upvote 0
Ok, so that means,
1) either the sheet name in the destination file is not named exactly as Additional Info Lookup
2) the previous couple of lines are not producing the desired result.

Is the sheet name in the destination file named exactly as Additional Info Lookup?
Yes
1658117047085.png


Edit: Sh*t. I just tried to edit the name and there was a space at the end of Lookup. That was probably the issue. I'll try now
 
Upvote 0
Is the name of the destination file
Additional Info Lookup Data.xlsx
 
Upvote 0
Edit: Sh*t. I just tried to edit the name and there was a space at the end of Lookup. That was probably the issue. I'll try now

I agree because that is about the only thing it can be if you reached that line in yellow.
 
Upvote 0
I agree because that is about the only thing it can be if you reached that line in yellow.
Yes that was it for that error. Now there is another error 😭
After deleting the space, your VBA works with the sample data perfectly, but it does not work with the original file. I left it at a random 59000 rows and it gives error. I did the F8 thing you showed me and it keeps looping in this part(like the note says). When the Yellow line goes over "Next", I press F8 and it goes back to yellow on the one in the picture.
1658117957150.png


If I set the breakpoint where the image below shows, it crashes automatically. Anywhere else above that and it won't crash, but it will go back to a loop above.
1658118414398.png
 
Upvote 0
You good now? Bedtime is arriving for me.
Sorry about that. You can come back to this tomorrow or next weekend if you have time. I don't want you to lose sleep because you wanted to help me. I really appreciate all the help so far.
 
Upvote 0
Once you hit that first yellow line in your last picture ... that is a loop to go through all of the rows of the csv file data.

At that point you can select a new break point of the red dot shown at the bottom of your last pic. Instead of continuing to hit the 'F8' button when you are in the code loop, you can tap the 'F5' button once and it should run all the way to where you set the new break point.
 
Upvote 0

Forum statistics

Threads
1,215,790
Messages
6,126,917
Members
449,348
Latest member
Rdeane

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