Excel function or VBA to compere between two columns.

Mohammad Alsolaiman
Mohammad Alsolaiman used Ask the Experts™
on
Hi,
in my Excle sheet
Which is happen first according StockMarketTime
The highest score in (highScore column) OR the lowest score in (lowScore column).
In my example, the equation should return with the row 7, of StockMarketTime = 12:00 and the highScore = 19, because it happen before the lowest score at row 11,  StockMarketTime = 02:00 and the lowScore= 12
So the comparison should always happen in between these two results only (the highest score in column StockMarketTime, and the lowest score in column  lowScore)
I need the result to highlight the row that match my needs.
please help.
there is attached Excel file
stockMarketsstock-market.xlsx
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
"Life would be infinitely happier if we could only be born at the age of eighty and gradually approach eighteen." - Mark Twain
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
Click the green button in this workbook which uses this macro.
Sub MaxBeforeMin()
Dim lngLowValue As Long
Dim lngHighValue As Long
Dim rngLow As Range
Dim rngHigh As Range

ActiveSheet.UsedRange.Cells.Interior.Color = 16777215

' Find the row containing the lowest value in column D
lngLowValue = WorksheetFunction.Min(Columns("D"))
Set rngLow = Range("D:D").Find(lngLowValue)

' Find the high row between row 4 and the row with the lowest value
lngHighValue = WorksheetFunction.Max(Range("C4:C" & rngLow.Row))
Set rngHigh = Range("C:C").Find(lngHighValue)

Range(Cells(rngHigh.Row, "B"), Cells(rngHigh.Row, "D")).Interior.Color = 5287936
End Sub

Open in new window

29167162.xlsm
Mohammad Alsolaimanapplication programmer

Author

Commented:
wonderful Martin Liss
Martin Liss"Life would be infinitely happier if we could only be born at the age of eighty and gradually approach eighteen." - Mark Twain
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
You’re welcome and I’m glad I was able to help.

If you expand the “Full Biography" section of my profile you’ll find links to some articles I’ve written that may interest you.

Marty - Microsoft MVP 2009 to 2017
              Experts Exchange Most Valuable Expert (MVE) 2015, 2017
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2018
              Experts Exchange Top Expert VBA 2018
              Experts Exchange Distinguished Expert in Excel 2018
Mohammad Alsolaimanapplication programmer

Author

Commented:
EXTREMELY HELPFUL

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial