brandonrlz
New Member
- Joined
- Jul 29, 2011
- Messages
- 30
So I'm creating an output based on a combo box filter; however, I can't seem to figure out why my code isn't working...everything seems to be defined correctly, but I keep getting a "Compile Error: Do without Loop"
Going through my code my thinking was based on the redundancy of the "End IF" statement; however, if I remove this I receive a separate error "Block If without If"
At this point I'm not exactly sure what the problem could be....
Code:
Sub dataOutput()
'
' dataOutput Macro
'
'
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("Sheet1").Range("G8")
Set MonthCell = Sheets("Sheet1").Range("G9")
Set YearCell = Sheets("Sheet1").Range("G10")
Set ResultRow = Sheets("Sheet2").Range("A7")
Set ResultRowRange = Sheets("Sheet2").Range("A7:D400")
' Find the column that contains the year going out to column 100
Set DateRow = Sheets("Sheet1").Range("A1")
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)
End Sub
Going through my code my thinking was based on the redundancy of the "End IF" statement; however, if I remove this I receive a separate error "Block If without If"
Code:
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
At this point I'm not exactly sure what the problem could be....