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
 
You should never hit that section of code if you are clicking on the button that was created on Sheet1.
Can you post a pic of the button you are clicking on?
Like I said on Post #21. I do not reach that code by clicking on the button. I only reach it when I click "play" on the module itself.
When I click on the button I only get the "Subscript out of range" error.
1658114490645.png
 
Upvote 0

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
That pic you are showing has the tab name at the bottom of 'Sheet1'?
 
Upvote 0
Ok set a break point (red dot) at the point shown in the pic below.

That is in the sheet1 module code.

After you do that, click the button on sheet1 and let me know if the code stops at that line with the red dot at the beginning of it.

Capture.PNG
 
Upvote 0
Perfect! Now tap the 'F8' button. The yellow line should advance to the next line of code.

Tap the 'F8' button again. This is called stepping through the code.

Each time the yellow line advances, tap the 'F8' button again ... let me know what line it produces the error on.
 
Upvote 0
Perfect! Now tap the 'F8' button. The yellow line should advance to the next line of code.

Tap the 'F8' button again. This is called stepping through the code.

Each time the yellow line advances, tap the 'F8' button again ... let me know what line it produces the error on.
This is the last yellow line. After this, it triggers the error

1658115777713.png


1658115820480.png
 

Attachments

  • 1658115755165.png
    1658115755165.png
    29.1 KB · Views: 2
Upvote 0
I am confused ... the line in yellow when executed 'F8' is when the error occurs?
 
Upvote 0
Your answer, I hope is yes, because the following line of 'StartRow = 2' will not produce that error.
 
Upvote 0
I am confused ... the line in yellow when executed 'F8' is when the error occurs?
Apologies for explaining badly.
So the yellow line goes down to the next line when I press F8 like you said.
After I press F8 again after the one in yellow in the picture, the error triggers and nothing shows as yellow anymore.
 
Upvote 0

Forum statistics

Threads
1,215,759
Messages
6,126,730
Members
449,333
Latest member
Adiadidas

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