Originally Posted by
tallboyz
Which cell should I place that formula using the example workbook I attached? The formula as is does not yield the desired result. Cells A26:U35 in the example workbook "Data" tab shows the desired output that I'm looking for.
Essentially, the VBA would need to create the "Average Salary" account variable by position, copy the Department and Region intersection description into the adjacent cells, then calculate the Average Salary amount by month.
I can do this using a calculated field in a pivot table, but would prefer an automated solution via VBA as this template will be used by multiple users who will have different datasets of Total Salary and Headcount by position that may change frequently.
you already have the formulas that you need at the bottom of the sheet named data. so essentially all you need to do then is forget about the vlookup() i wrote and loop through everything. I know there are easier ways to do most of the automation that I have come up with below because I mostly write patterns all the time, but if you want to do it the way I have written it, go ahead:
the code does not actually execute though, and I tried to look up the answer to this nonsense but could not find it anywhere. this line of code:
throws an overflow error the first time it encounters a ''Total Salary'' value of ''0''. I have no idea what the issue could be, other than how you have those cells formatted. You have it set to custom, and the data mask is huge. I would recommend not doing that. Personall, I have never used a custom data mask in Excel ever in my lifetime. Furthermore, I know the code works because if you change the offending line to the following (or any literal number) it works just fine:
so....obviously all this code will satisfy the workbook you uploaded. You will have to change it to suit your needs with the actual workbook you have or will be working with in the future.
One of the other reasons I wrote the code this way is to illustrate how a lot of business software is written. And that is to say, very cheaply. At the bottom of this post is a great example of cheap database software that was bought by the biggest website hosting company in the world. Notice the huge number of iterations of the same SQL statement, line after line, as a confirmation by the program to execute a ONE LINE query. Interesting isn't it? So, I hope the code provides some value to you. Good luck with it!
Bookmarks