I've done some calculations where the output consists of 6 scenarios of 6000 rows of results in 12 separate worksheets. The output for each scenario looks like this, where columns B,C,D would contain values for RMSE, MAE and MASE for scenario 1 and columns G,H,I would contain the values for scenario 2, etc, for 6000 rows and 6 scenarios. What I would like to do is compare the values for RMSE in each row, find the minimum value and highlight the cell. Then do the same for MAE and MASE. The problem is the cells aren't contiguous so a Range over all the cells in the row won't give me what I want.
I've written some code below just for the RMSE calculation just for the first three rows, but the rng search doesn't give me what I need.
Code:
SES RMSE MAE MASE Mean RMSE MAE MASE Naive RMSE MAE MASE
Test 8.331 8.331 0.458 Test 8.333 8.333 0.545 Test 0 0 0
Test 0.333 0.333 0.458 Test 0.333 0.333 0.6 Test 0 0 0
Test 2 2 0.512 Test 2 2 0.667 Test 2 2 0.512
Test 32.086 32.086 0.528 Test 32.083 32.083 0.75 Test 0 0 0
Test 0.417 0.417 0.458 Test 0.417 0.417 0.6 Test 0 0 0
Test 6.505 6.505 1.988 Test 3 3 0.667 Test 20 20 6.111
Test 0.167 0.167 0.458 Test 0.167 0.167 0.545 Test 0 0 0
I've written some code below just for the RMSE calculation just for the first three rows, but the rng search doesn't give me what I need.
Code:
Sub Highlight_Minimum_Metric()
Dim totalrows As Long, irow As Long, minRMSE As Double, rng As Range, cell As Range
totalrows = Sheets("h=1").UsedRange.Rows.Count
For irow = 2 To 4
Set rng = Range(Cells(irow, 2), Cells(irow, 29))
minRMSE = Application.WorksheetFunction.Min(Cells(irow, 2), Cells(irow, 7), Cells(irow, 22), Cells(irow, 27))
For Each cell In rng
If cell.Value = minRMSE Then
cell.Font.Color = vbRed
End If
Next cell
Next irow
End Sub
Last edited: