Hello everybody, I have been struggling for a while with a Macro I'm trying to build; I've been stuck for 2 days, searching for a solution in the web and have not find success. Although for the last several times I've run the code (directly in the VBA Window) I keep getting different results, with the code and the database unchanged.
The code (at the end of the post) gathers information from a database (located in Sheet "Lista"), which has information in different columns such as Date, Family of product, product description (column F), unitary price (column G), units sold (column H), exchange rate (column I), sale in MXN (which is the product of the last three 3 columns; column J), and so on. First and foremost the code runs a Sub called ordenAlfab(), which simply sorts the product description column in Alfabetic order, and all the other columns in the dataset accordingly. The code of such Sub is the following:
After sorting, the main code will search for the duplicates of the product, sum the sales per unit in MXN and the units sold, and calculate a percentage of the sale of each product in comparison to the total amount of sales. All this new information is pasted and calculated in the Sheet "Reporte". Lastly, the list generated in "Reporte" will sort the column of % of total sales from Largest to Smallest (and all the other columns accordingly).Please Login or Register to view this content.
Every time I run the code I get different results. Sometimes I get the correct results, sometimes the % of total sales calculations are done incorrectly, sometimes the numbers are correct but the final dataset is not being sorted from largest to smallest, and so on.
Any idea of why this inconsistency is happening? Also, if you guys have any suggestions for changing the code for any better solutions, such suggestions are also welcomed.
Thanks a lot in advance, have a great day!
Please Login or Register to view this content.
Bookmarks