VBA Compile Error for Combo Box Output

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" :confused:

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....
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
For each Do, you need a Loop. You have three Do statements and only two Loop statements.

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

[COLOR="Magenta"]Do[/COLOR]
    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)
        [COLOR="Magenta"]Do[/COLOR]
            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
                [COLOR="Magenta"]Do[/COLOR]
                    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)
                [COLOR="Red"]Loop[/COLOR] 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)
        [COLOR="Red"]Loop [/COLOR]Until IsEmpty(CustomerCol.Value)

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,567
Messages
6,179,571
Members
452,927
Latest member
whitfieldcraig

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