Attached is a spreadsheet with three tabs. The first is raw data exported from Access into Excel. The second tab is the same data, after inserting subtotals, formatting fill and borders, and inserting text in a few locations. The third tab is the VBA code that formats the first sheet to look like the second sheet. I recorded a macro while in Excel, then took the resulting VB code and put it into Access, where I made a few required changes.
I am sure there is a better and programmatic way to do the formatting instead of the 700+ lines of code. What I am doing, and the order in which I am doing it is:
1. Export the data to Excel
2. Open Excel
3. Insert subtotals
4. Based on where the subtotals occur,
a) delete replicated data in Columns A and B
Insert text identifying the totals line
c) format column A and subtotal line with border and fill color
d) format column B and subtotal line with border and fill color and font type (underline)
5. Insert lines at top of sheet
6. Put title in A1
I am pretty sure there is a way to programmatically find the subtotal lines and then format the columns and cells based on the rows where the subtotals occur, but I don’t know how to find it, and once found how to tell Excel to fill, format etc. the cells with the appropriate color, border and fonts. In addition to the obvious drawback of a lot of lines of code, if a new continent, country or city is added in Access, when the data is exported to Excel the subtotals lines will no longer be in the same row, so the existing VBA code would be a disaster.
Is there a good place or resource to go to get ideas? Does anyone here have a suggestion?
Thanks in advance for your consideration.
Ken