I’ve gotten myself into quite the mathematical “pretzel” and not sure how to get out of it.
I have a huge workbook that contains UPC codes in column D and Prices in column J. I use the following VBA code within a larger macro to count the number of matching prices within all instances of the same UPC. So basically, it’s a FOR EACH unique product, COUNT the number of identical prices.
For R = 2 To UBound(Arr, 1) 'Count the number of matching prices for each unique UPC Cells(R, 18) = WorksheetFunction.CountIfs(Columns(4), Cells(R, 4), Columns(10), Cells(R, 10)) Next R
The Excel formula equivalent, if it would be easier to envision, is:
And now to my problem. I need to also find/count prices for the same product that are within +/- 10% of the price being compared (the J2 part of the formula).
So basically, for a $1.00 product, any price between $.90 and $1.10 should be counted.
Is this even possible or am I just going about it all wrong?
EDIT: Contextual FYI – this is a workbook of 4,000+ unique UPCs over 30,000+ rows if that makes any differences in the best approach you would recommend for this problem.
The formula equivalent would be:
=COUNTIFS(D:D,D2,J:J,">="& 0.9*J2,J:J, "<=" & 1.1*J2)