jhg1226
09-27-2010, 05:28 PM
The sub pasted below works just fine, but I do not understand why. Can anyone explain to me what the line of code highlighted in blue is doing?
Sub QuarterSales()
Dim RowCount As Integer
Dim QtrCount As Integer
Dim QtrSales(0 To 3) As Long
'Loop for every row (Region)
For RowCount = 2 To 41
'Loop to Calculate Totals for all quarters
For QtrCount = 0 To 3
QtrSales(QtrCount) = Cells(RowCount, (2 + (QtrCount * 3))).Value + Cells(RowCount, (3 + (QtrCount * 3))).Value + Cells(RowCount, (4 + (QtrCount * 3))).Value
Next QtrCount
'Checking condition Q1 > Q2 > Q3 > Q4
If QtrSales(0) > QtrSales(1) Then
If QtrSales(1) > QtrSales(2) Then
If QtrSales(2) > QtrSales(3) Then
'Applying RED color
Cells(RowCount, 1).Interior.ColorIndex = 3
End If
End If
'Checking condition Q1 < Q2 < Q3 < Q4
ElseIf QtrSales(0) < QtrSales(1) Then
If QtrSales(1) < QtrSales(2) Then
If QtrSales(2) < QtrSales(3) Then
'Applying BLUE color
Cells(RowCount, 1).Interior.ColorIndex = 5
End If
End If
End If
Next RowCount
End Sub
Sub QuarterSales()
Dim RowCount As Integer
Dim QtrCount As Integer
Dim QtrSales(0 To 3) As Long
'Loop for every row (Region)
For RowCount = 2 To 41
'Loop to Calculate Totals for all quarters
For QtrCount = 0 To 3
QtrSales(QtrCount) = Cells(RowCount, (2 + (QtrCount * 3))).Value + Cells(RowCount, (3 + (QtrCount * 3))).Value + Cells(RowCount, (4 + (QtrCount * 3))).Value
Next QtrCount
'Checking condition Q1 > Q2 > Q3 > Q4
If QtrSales(0) > QtrSales(1) Then
If QtrSales(1) > QtrSales(2) Then
If QtrSales(2) > QtrSales(3) Then
'Applying RED color
Cells(RowCount, 1).Interior.ColorIndex = 3
End If
End If
'Checking condition Q1 < Q2 < Q3 < Q4
ElseIf QtrSales(0) < QtrSales(1) Then
If QtrSales(1) < QtrSales(2) Then
If QtrSales(2) < QtrSales(3) Then
'Applying BLUE color
Cells(RowCount, 1).Interior.ColorIndex = 5
End If
End If
End If
Next RowCount
End Sub