Compare a cell value with all the following cell values

ibmy

Board Regular
Joined
Mar 4, 2020
Messages
134
Office Version
  1. 2016
Platform
  1. Windows
Low.xlsb
BF
1OfferLow
21.30 
31.70 
41.60 
52.40 
60.90 
70.30 
80.80 
90.20Low
100.20Low
111.80 
121.40 
133.00 
141.00Low
151.30 
161.10Low
171.90 
181.70Low
192.00 
202.10 
212.30 
221.70Low
231.80Low
241.90Low
252.50
Sheet4
Cell Formulas
RangeFormula
F2:F24F2=IF(B2<=MIN(B3:B$25),"Low","")

When there are no value lower than a cell value, assign ("Low"), else ("").
The formula start at row 2 until second last row( last row - 1 ).

Currently, there is no problem with the formula, the formula work fine but it take long time/sometime Excel hang for 250k row data, for data less than 60k it is fine.
Expected to have VBA solution or any other alternative formula.

I think current formula not good at handling "else" part (""). I do not know how the formula work detail in Excel, but I assume, let say :
Current cell value B2 is 1.30, at B6 value is 0.90 which is lower than B2, assign F3 ("") then check/loop next new cell B3 instead of going through
until last row B25 (B$25) / B7-B25.
For "Low" part, the formula work as intended, it need to check all following cell/value until last row to confirm a value is Low.
 
Last edited:

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Hi, here's one option you can try:

VBA Code:
Sub m()
Dim v As Variant, i As Long, u As Long, low As Double
v = Range("B2:B" & Range("B" & Rows.Count).End(xlUp).Row)
u = UBound(v)
low = v(u, 1)
v(u, 1) = ""
For i = u - 1 To 1 Step -1
    If v(i, 1) <= low Then
        low = v(i, 1)
        v(i, 1) = "Low"
    Else
        v(i, 1) = ""
    End If
Next i
Range("F2").Resize(u).Value = v
End Sub
 
Upvote 1
Solution
Thank you Master @FormR
The code take a second to produce the result for 250k+ row data.

How can the code produce the result faster than the formula I apply before?
 
Upvote 0
How can the code produce the result faster than the formula I apply before?
Hi, it's the MIN() function that's probably killing it, the last cell that formula is in needs to check 250,000 cells, the next one up 249,999 the next one 249,998, the next 249,997 - that's already nearly a million cell reads are we're only 4 formulas into the 250k you have!
 
Upvote 1
Upvote 1

Forum statistics

Threads
1,224,812
Messages
6,181,091
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top