How to highlight a row in a listview?

How to find max/min value using VBA for next loop...? and highlight the row with colour?

  • i) Write a VBA code to fill in the student numbers in the second column using For-Next loop; at the same time, input the marks for each student using input box and fill them in the third column. (ii) Calculate the average marks of the students using For-Next loop and output it to a cell. (iii) Using For-Next loop, find out the maximum and minimum marks and highlight the rows using red and green colour, respectively. i have done part 1 and part 2.. no sure how to do part 3

  • Answer:

    Here is one way: Sub MinMax() Dim LastRow LastRow = Range("C" & Rows.Count).End(xlUp).Row For i = 1 To LastRow If Cells(i, "C").Value = Application.Max(Range("C1:C" & LastRow)) Then Cells(i, "C").Interior.ColorIndex = 3 ElseIf Cells(i, "C").Value = Application.Min(Range("C1:C" & LastRow)) Then Cells(i, "C").Interior.ColorIndex = 4 Else Cells(i, "C").Interior.ColorIndex = xlNone End If Next End Sub

Ray at Yahoo! Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.