Creating a macro compatible with several similar but not identical spreadsheets

mmahercpa

New Member
Joined
Dec 29, 2015
Messages
4
Hello,

For my job, I work on audits of various companies. Several of the companies are construction companies with similar-looking financial statements. I have the spreadsheets for each company with ten years of financial data and analytical formulas that contains graphs linked to the data for the last five years. I want to create a macro that will add a new tenth year column and take out the current first year column to maintain ten years of data, but I need to maintain five years of data for the graphs. I have been able to do this for one company through the macro recorder and some code manipulation in VBA (I am still a beginner at macros), but the macro is not fully compatible with the other companies due to slight differences in line items in the data or formulas. Does anyone have any ideas of how to generalize the macro to work for each company without writing a totally new code for each one?

Thank you

p.s. The code is very long and complex, so I will only include portions of it if necessary.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Welcome to the Board!

Are the column headers consistent? If so, then you can use Application.Match("Header Name", Range("1:1"),0) to find the header you need to delete regardless of where it is.

E.G.

x = Application.Match("Header Name", Range("1:1"),0)
Columns(x).EntireColumn.Delete

HTH,
 
Upvote 0
Thank you Smitty,

Yes, the columns for each company are exactly the same. From left to right, every company appears identical. It is from top to bottom that the differences appear. For example, some companies have inventory, and some do not. That lends itself to a new row for those companies that do have it. Since some will have inventory, they will have various inventory ratios that the other companies will not have. However, there a few "average" ratios that require data from the year before to compute correctly. Because of those, I have those values copied and pasted special as values only. But I don't want that happening with all of the formulas, just the three or four that are "average" ratios.

Thank you
 
Upvote 0
I am using Windows 7 and Excel 2013, if that helps anyone.
Also, I cannot figure out how to paste a screenshot of the spreadsheet (or a portion thereof).

Thanks,

mmahercpa
 
Upvote 0

Forum statistics

Threads
1,216,174
Messages
6,129,296
Members
449,498
Latest member
Lee_ray

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