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
Related Q & A:
- How to calculate max/min scales on a scatter plot?Best solution by Cross Validated
- How I can find string in excel with vba?Best solution by Stack Overflow
- How to find the derivative without using a symbolic function in Matlab?Best solution by Stack Overflow
- How to get the column value when a row is selected in wpf listview?Best solution by Stack Overflow
- how to select max and min?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.