Dear VBA Developer,
The attached Excel file contains two sheets: Master Data and RM Purchase.
In the Master Data sheet, Column B lists the Project Locations, with consumption data spanning from columns 3 to 23.
In the RM Purchase sheet, Column 3 also features Project Locations, with price...
G refers Qty and E refers Comapny Name
So the real file Y refers to Qty and C refers to Company name.
But still output prints Zero in all cells.
Sub Cost_Calculation()
Dim D@(), B, E, F, R&, L, M@
Dim wsMaster As Worksheet, wsPurchase As Worksheet
Dim lastRowMaster As Long...
I changed this and the output is zero again.
E = Evaluate(Replace("IF(Y8:Y" & wsPurchase.Rows.Count & ">0,D8:D" & wsPurchase.Rows.Count & ","""")", "#", wsPurchase.Rows.Count))
Boss, please modify the code to function correctly with my actual file.
Boss, I've just changed to `.count` at the end of the code line, but it's showing an error.
E = wsPurchase.Evaluate(Replace("IF(Y8:Y#>0,D8:D#,"""")", "#", .Count))
Boss, I've transferred the code to my actual file, but all the output values are zero. Please see the snapshot. I may have made some mistakes while rewriting the code. Could you please check it?
Sub Cost_Calculation()
Dim D@(), B, E, F, R&, L, M@
Dim wsMaster As Worksheet, wsPurchase As...
It's functioning, boss. I'll transfer it to the actual file and will return if I encounter any issues. Beyond hitting a 'like', there's not much else I can do.
Boss, thanks for your response!
I totally get what you're saying. Yes, it’s basically a FIFO-style calculation, and I see why it might feel unnecessary to use VBA for it. The reason I was aiming for a VBA approach is because the data I’m working with can change frequently – company names can...
In the attached sheet K4, I have used a formula to calculate the consumption cost for Company A.
In the snapshot below, column D, I manually added the values from columns F and G, which represent the purchase quantity and price, to calculate the cost.
The consumption occurred in quantities of...
In the initial post, I have detailed my requirements with an attachment and provided the expected results through an Excel formula. Please inform me of any additional information you need to provide the VBA code, with or without a dictionary.
Could you include the IF statement and provide the formula that would yield the expected outcome?
I meant easy understandable codes that I can transfer to my real file.
I have already elaborated in the initial post. Should someone require further details, I will explain the specifics in...
Boss, Thanks for your reply (Expect your reply)
The reason I’m asking for a VBA code is that the data can get messy over time. The company names in columns B and E won’t always be in order—they might get shuffled around (like AABBBCADDEFGDFG). If I just use formulas, I’d have to adjust them...
Here is the link to the post in the VBA Macro section for your information.
https://chandoo.org/forum/threads/vba-code-to-calculate-consumption-cost-by-matching-company-names-and-purchase-quantities.57862/
Thank you for your time and effort on my post. If your solution can be easily transferred to my original file, then I must use it. However, my actual file contains many companies and many RMs, so creating a table for each company would be difficult for me. As you suggested, I have already posted...
Dear VBA Code Experts,
I need a VBA code to dynamically calculate the consumption cost for multiple companies based on matching company names, prices, and purchase quantities. The input data includes company names (B4) with their respective consumption quantities (C4) and company names (E4)...