Loop without a Do error

omnisautnihil

New Member
Joined
May 13, 2011
Messages
19
Hello, I am just now beginning to learn how to write Macros and I have been working on one that is being used to search through one document for a value in another and labeling an adjacent cell with the counter. All of my research points to people who do not have EndIf used appropriately but I do not see how mine is similar. Can anyone see why my code won't compile with "Loop with no Do" error?

*****************************
Sub Sorting()

Windows("File1.xls").Activate
Dim Count As Integer
Count = -1
Dim gCount As Integer
gCount = 0
Dim ICount As Integer
ICount = Count - gCount

Range("D5").Select
Dim rFound As Range

Do Until Selection.Value = ""
Count = Count + 1
Range("D5").Offset(Count, 0).Select
If Selection.Value = "General" Then
gCount = gCount + 1
Loop
ElseIf Selection.Value = Selection.Value.Offset(-1, 0) Then
Loop
Else
Selection.Value.Copy
Windows("ReviewAide.xls").Activate
Set rFound = Columns(2).Find(What:=Selection.Value, After:=Range ("B832"), LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows,_ SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If Not rFound Is Nothing Then
Selection.Offest(0, -1).Select = "Issue " & ICount
ActiveCell.FontStyle = "Bold"
Windows("File1.xls").Activate
Else
MsgBox (Selection.Value & "is not a valid ID.")
Exit Do
End If
End If
Loop
MsgBox ("DONE!")
End Sub

**************************************************

If something needs explanation just let me know, but I'm only looking for why it does not understand my Loop statements where I want to break inside the if statements.
 
Another correction:

Code:
    ElseIf Selection.Value <> Selection.Value.Offset(-1, 0) Then
        temp = Selection.Value
        Windows("ReviewAide.xls").Activate
        Set rFound = Columns(2).Find(What:=temp, LookIn:=xlValues)
        
        If Not rFound Is Nothing Then
            With rFound.Offest(0, -1)
                .Value = "Issue " & iCount
                .Font.Bold = True
            End With
            Windows("File1.xls").Activate
        
        Else
            MsgBox ([COLOR=red][B]temp[/B][/COLOR] & "is not a valid ID.")
            Exit Do
        End If
    End If
 
Upvote 0

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
it is still giving me the same error for the rFound.Offset(0,-1) line.

I can put rFound.Offset(0,-1).Select

or use the With function and it says the same thing "Object doesnt support this property or method." I definitely have rFound defined as a range up above.
 
Upvote 0
it is still giving me the same error for the rFound.Offset(0,-1) line.

I can put rFound.Offset(0,-1).Select

or use the With function and it says the same thing "Object doesnt support this property or method." I definitely have rFound defined as a range up above.

Strange... try replacing the With block to:
Code:
            With rFound
                .Offest(0, -1).Value = "Issue " & iCount
                .Offset(0, -1).Font.Bold = True
            End With
 
Upvote 0
Same thing..I'm assuming that this is a situation where the highlighted section is not necessarily the cause of the error. I would assume there is something wrong in my find function or my If Not fucntion.

As I have ZERO clue how the find function works I would guess there.

Work day is over and I wont have access to this over the weekend. I will come back to it on Monday but if anyone sees a possible solution, feel free to post!!

Thank you so much MrKowz for your help thusfar.
 
Upvote 0

Forum statistics

Threads
1,224,545
Messages
6,179,432
Members
452,915
Latest member
hannnahheileen

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