VBA Data Pull

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:

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
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,222,196
Messages
6,164,519
Members
451,900
Latest member
lamski

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top