Hello Everyone,
I have this application working 99%. I'm very new at VBA still so I may not have efficient coding, but it is almost working the way I want.
I am setting this up for someone else to use so that is why it is heavily commented.
*NOTE* the "Excel" sheet data is cleaned and sorted by InvoiceNumber and DepartmentCode MANUALLY prior to running the code. "I'm not that good yet" LOL
What the code does:
In nutshell:
The VBA code copies all the records from A to H, with the same invoice number, on the "Excel" sheet into a copy of the "Master" Sheet in A to H.
Then renames that sheet and saves it.
In Detail:
- The code takes the "Master" sheet and makes a copy
- Then loops through each record in the "Excel" sheet
- looks at invoice numbers and loops to copy all records, from A to H, with the same invoice number from "Excel" over to the newly A to H on the newly created copy of "Master" sheet
- then renames the newly created sheet the invoice number (which in hindsight is probably not necessary now that I think of it)
- once done it adds the excel "Subtotal Feature" to the sheet, saves the sheet as a new workbook then deletes the sheet.
In the end there should be 11 workbooks created and renamed:
CC PTS Ontario Fuel Escalation Charges Invoice 102001-Fuel.xlsx ( 1 record)
Cash Broker PTS Ontario Fuel Escalation Charges Invoice 102002-Fuel.xlsx ( 1 record)
Cash Broker PTS Ontario Fuel Escalation Charges Invoice 102003-Fuel.xlsx ( 1 record)
Cash Broker PTS Ontario Fuel Escalation Charges Invoice 102004-Fuel.xlsx ( 1 record)
Cash Broker PTS Ontario Fuel Escalation Charges Invoice 102005-Fuel.xlsx ( 1 record)
Cash Broker PTS Ontario Fuel Escalation Charges Invoice 102006-Fuel.xlsx ( 1 record)
Ornge Fuel Escalation Charges Invoice 102007-Fuel.xlsx ( 1 record)
UHN Dedicated 440002090 Fuel Escalation Charges Invoice 102008-Fuel.xlsx ( 3 records)
LHC 607012201020 Fuel Escalation Charges Invoice 102009-Fuel.xlsx ( 6 records)
SJHH Hamilton - Charlton - Continuing Care Fuel Escalation Charges Invoice 102010-Fuel.xlsx ( 1 record)
Cash PTS Ontario Fuel Escalation Charges Invoice 102011-Fuel.xlsx ( 1 record)
So works as I expected after about a dozen tests.
The Problem is when it gets to the last invoice number (102011) it doesn't subtotal it and save it.
It creates the sheet for the final Invoice then quits the sub.
I tried adding changing
to
, which worked, but then errored out because there were no more rows with invoice numbers.
That is my problem. I just need this loop to finish out the last invoice record.
Let me know if you need more clarification. Again, sorry for all the comments too.
Thank you,
Gray
Bookmarks