PDA

View Full Version : VBA Code Needed



tonyadams
04-01-2024, 01:40 AM
I'm working on an Excel spreadsheet to track sales data. I have columns for product name, quantity sold, and unit price. I want to create a macro using VBA code that will:
Calculate the total sales for each product by multiplying quantity by unit price.
Identify the top 3 best-selling products based on total sales.
Can you help me write the code to achieve this functionality?
Retro Bowl College (https://retrobowlcollege.io)

Aussiebear
04-01-2024, 02:22 AM
What makes you think you cant do this by formula?

georgiboy
04-01-2024, 04:35 AM
Would also be a good idea to share a spreadsheet with some dummy data, you could lay the data out as you have it currently. Members here will be more likely to assist if they don't have to recreate your scenario.

As Aussie has pointed out above, I am sure this could be done with formula, this would allow for your stats to update with future data being added.

jdelano
04-01-2024, 01:04 PM
You could do this with formulas as Aussiebear alluded to.

This just has price * Sold, then uses SortBy function to sort the total descending and finally a section that just uses cell linking to the top 3 rows of the sorted section.

You can do this with VBA if you want to, if there is more you would like to control or want to switch things up later.

June7
04-01-2024, 09:06 PM
Forcing Excel to perform as a database could be wrong path. Very large workbooks can become sluggish to the point of non-functional. How much data do you expect to collect? Are you documenting discrete transactions or just aggregated values and you will be changing the values periodically? "Tracking" implies discrete transactions but I suspect not since you don't mention attributes of OrderNum, OrderDate, CustomerID.

If you stick with Excel, consider learning Power Query.

Bob Phillips
04-02-2024, 03:42 AM
Chuck it into a pivot table. No code, no formulas, aside from a calculated column.

Paul_Hossler
04-03-2024, 09:33 AM
Like Bob says, a pivot table would be the best / easiest / no VBA required way to go

It would give you the most flexibility for reporting and analysis

I would think that there's more information you'd want to trck, e.g. sales date, customer, etc.

31479

Aussiebear
04-03-2024, 02:27 PM
I think the OP has lost interest in this thread....