Thread

VBA Sales Data Analysis Project

A practical project focused on analyzing and summarizing sales data using VBA loops and arrays.

Empty image or helper icon

VBA Sales Data Analysis Project

Description

In this project, you will learn how to handle multi-dimensional arrays to store and manipulate sales data across different years and months. You'll implement loops to calculate total sales and print the results using Debug.Print. The project aims to provide a hands-on understanding of data processing in VBA.

The original prompt:

Can you give me a complete overview about this particular code, while teaching me all parts of it.

Sub ComplexLoopExample() Dim sales(1 To 5, 1 To 12) As Double Dim yearTotal(1 To 5) As Double Dim monthTotal(1 To 12) As Double Dim i As Integer, j As Integer

' Populate the sales array with some data (for illustration)
For i = 1 To 5
    For j = 1 To 12
        sales(i, j) = (i * 100) + (j * 10) ' Sample data
    Next j
Next i

' Calculate yearly total sales
For i = 1 To 5
    yearTotal(i) = 0
    For j = 1 To 12
        yearTotal(i) = yearTotal(i) + sales(i, j)
    Next j
Next i

' Calculate monthly total sales across all years
For j = 1 To 12
    monthTotal(j) = 0
    For i = 1 To 5
        monthTotal(j) = monthTotal(j) + sales(i, j)
    Next i
Next j

' Output the results
Debug.Print "Yearly Totals:"
For i = 1 To 5
    Debug.Print "Year " & i & ": " & yearTotal(i)
Next i

Debug.Print "Monthly Totals:"
For j = 1 To 12
    Debug.Print "Month " & j & ": " & monthTotal(j)
Next j

End Sub

Content