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
 
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.
That's what I was doing, but like I said, seems like that one in red in the picture is the issue. Error triggers when I have that as the breakpoint.


1658119165389.png
 
Upvote 0

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Without seeing the rest of your CSV data, it sounds like something in the CSV data is not being 'handled properly' & probably looking to add more columns than what are expected.

To see if this is the problem, try changing the following line, which is 1 line above the most recent code you pictured:

VBA Code:
    ReDim Partitioned_CSV_FileArray(1 To UBound(All_CSV_RowsFromCSV_FileArray), 1 To 21)        ' Set rows/columns for Partitioned_CSV_FileArray

to:

VBA Code:
    ReDim Partitioned_CSV_FileArray(1 To UBound(All_CSV_RowsFromCSV_FileArray), 1 To 30)        ' Set rows/columns for Partitioned_CSV_FileArray

If that allows the code to finish, then we will have to figure out what has not been handled properly in the CSV data. You will be able to spot the issue in the destination sheet by any lines of data that extend past the U column. ;)
 
Upvote 0
Without seeing the rest of your CSV data, it sounds like something in the CSV data is not being 'handled properly' & probably looking to add more columns than what are expected.

To see if this is the problem, try changing the following line, which is 1 line above the most recent code you pictured:

VBA Code:
    ReDim Partitioned_CSV_FileArray(1 To UBound(All_CSV_RowsFromCSV_FileArray), 1 To 21)        ' Set rows/columns for Partitioned_CSV_FileArray

to:

VBA Code:
    ReDim Partitioned_CSV_FileArray(1 To UBound(All_CSV_RowsFromCSV_FileArray), 1 To 30)        ' Set rows/columns for Partitioned_CSV_FileArray

If that allows the code to finish, then we will have to figure out what has not been handled properly in the CSV data. You will be able to spot the issue in the destination sheet by any lines of data that extend past the U column. ;)
Hi,
So it works up to here(image) with a breakpoint, but if I press F8 after this, it gives the same error.
1658167037721.png



1658167102838.png
 
Upvote 0
Not sure what other assistance I can offer without having a csv file that produces the issues you are facing.
 
Upvote 0
Not sure what other assistance I can offer without having a csv file that produces the issues you are facing.
I believe I found the issue. Please try to use this sample and run your macro. It will run it, but look what happens with the values on the H column(PO #). There are some that are even longer on the PO # column.


Edit:

P.S. In case this matters: Depending on the customer, the same could happen on columns F and G. Not as many as in column H, but some rows could have 2 or 3 references in the same cell separated by a comma, space or underscore. They also use colon and dashes, but not for different references, but the same reference could have colon or dashes as part of the name.
 
Last edited:
Upvote 0
Got the same error that you have been reporting.
Now I need to track down what is causing it & how to handle it properly.
 
Upvote 0
Got the same error that you have been reporting.
Now I need to track down what is causing it & how to handle it properly.
Thank you so much and apologies for all the issues I'm giving you Johnny 😞
 
Upvote 0

Forum statistics

Threads
1,215,438
Messages
6,124,873
Members
449,192
Latest member
MoonDancer

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