[Back to Excel VBA Sample Code]
This is a simple Excel VBA counter that can count the number of passes and the number of failures for a list of marks obtained by the students in an examination. The program can also differentiate the passes and failures with blue and red colors respectively. Let's examine the code below:
|
This program combines For..Next and If ...Then...Else statements to control the program flow. If the value in that cell is more than 50, the value of counter is increased by 1 and the font color is changed to blue (the colorIndex is 5) , otherwise there is no increment in the counter and the font color is changed to red (ColorIndex=3). The output is as shown in Figure 9.1
Figure 9.1
 
[Back to Excel VBA Sample Code] Copyright ® 2008 Dr.Liew Voon Kiong . All rights reserved Contact: admin@excelvbatutor.com [Privacy Policy]