brandonrlz
New Member
- Joined
- Jul 29, 2011
- Messages
- 30
So I'm a little new with VBA and for the most part do alright; however, I'm having an issue and need some guidance on how to do this.
I basically have some form control drop-downs that allow me to pick a client name, another for month, and another for the year; at which point you can then click a button to pull the data.
I'm able to get one months worth of data pulled, but I can't seem to figure out how to make it pull different months. Any help or direction would be great!
Here's my code:
I basically have some form control drop-downs that allow me to pick a client name, another for month, and another for the year; at which point you can then click a button to pull the data.
I'm able to get one months worth of data pulled, but I can't seem to figure out how to make it pull different months. Any help or direction would be great!
Here's my code:
Code:
Sub dashboardOutput()
'
' dasboardOutput Macro
' Provide an output of data based on selected filters.
'
Dim CustomerCell As Range
Dim MonthCell As Range
Dim YearCell As Range
Dim DateRow As Range
Dim ColumnDistance As Integer
Dim CustomerCol As Range
Dim ResultRow As Range
Dim ResultRowRange As Range
Set CustomerCell = Sheets("Formula List").Range("G6")
Set MonthCell = Sheets("Formula List").Range("G7")
Set YearCell = Sheets("Formula List").Range("G8")
Set ResultRow = Sheets("Dashboard").Range("B9")
Set ResultRowRange = Sheets("Dashboard").Range("B9:E400")
' Find the column that contains the year going out to column 100
Set DateRow = Sheets("PEPM Extract 2011").Range("A7")
ColumnDistance = 4
Do
If Year(DateRow.Value) = YearCell.Value And _
Format(DateRow.Value, "mmmm") = MonthCell.Value Then
End If
' found a matching date range
' loop on the values until you find a matching Customer
' stop when no more matching customer or blank customer
Set CustomerCol = DateRow.Offset(2, 0)
Do
If CustomerCol.Value = CustomerCell.Value Then
' Found a matching value, now loop until we we don't match any more
' and output matching information
Dim startingAddress As String
startingAddress = ResultRow.Offset(0, 2).Address
' clear the range
ResultRowRange.ClearContents
' fill with matching information
Do
ResultRow.Offset(0, 0).Value = CustomerCol.Offset(0, 0).Value
ResultRow.Offset(0, 1).Value = CustomerCol.Offset(0, 1).Value
ResultRow.Offset(0, 2).Value = CustomerCol.Offset(0, 2).Value
ResultRow.Offset(0, 3).Value = CustomerCol.Offset(0, 3).Value
Set CustomerCol = CustomerCol.Offset(1, 0)
Set ResultRow = ResultRow.Offset(1, 0)
Loop Until CustomerCol.Value <> CustomerCell.Value
ResultRow.Offset(0, 2).Value = "=sum(" + startingAddress + ":" + ResultRow.Offset(-1, 2).Address + ")"
Exit Sub
End If
Set CustomerCol = CustomerCol.Offset(1, 0)
Loop Until IsEmpty(CustomerCol.Value)
Set DateRow = DateRow.Offset(, ColumnDistance)
Loop Until DateRow.Column > 100
End Sub