Consulting

Results 1 to 2 of 2

Thread: Solved: Explain Code Please

  1. #1
    VBAX Newbie
    Joined
    Sep 2010
    Posts
    2
    Location

    Solved: Explain Code Please

    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

  2. #2
    VBAX Newbie
    Joined
    Sep 2010
    Posts
    2
    Location

    Figured it out

    The code calculates quarterly values by multipling the vale to obtain the column in which the months fall. Jan is in column B, Feb in C and March in D.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •