Loop Error in VBA

sasha1

New Member
Joined
Mar 11, 2009
Messages
1
I am a pretty inexperienced user of VBA but hoping someone can help... Why would I bet getting a "Loop without Do" error on the following code?

*********************
Sub OverUnder()

Sheets("Weekly Input Sheet").Range("B4").Select
CurrWkNum = ActiveCell.Value
Sheets("Sample File").Select

Do While Error = False
ActiveSheet.Next.Select
CurrSheetName = ActiveSheet.Name
Columns("E:E").Select
Selection.Find(What:=CurrWkNum, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 5).Select
If ActiveCell.Value > 0 Then
Range(Selection, ActiveCell.Offset(0, 3)).Select
Selection.Copy
Sheets("Profitability Dashboard").Select
Cells.Select
Selection.Find(What:="Which are over and by what %", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
ActiveCell.Offset(xlDown).Select
ActiveCell.Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Sheets(CurrSheetName).Select
Range("A5").Select
Range(Selection, ActiveCell.Offset(0, 3)).Select
Selection.Copy
Sheets("Profitability Dashboard").Select
Cells.Select
Selection.Find(What:="Which are over and by what %", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
ActiveCell.Offset(xlDown).Select
ActiveCell.Offset(0, -2).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Sheets(CurrSheetName).Select
Else
Loop

End Sub
****************

thanks in advance for the help!!!
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Because you don't have End If anywhere?

Try replacing Else with End If.:)
 
Upvote 0
Weclome to the board!

At a quick glance, and without copying and testing your code I would say your error is in the do line, should be Do, not Do While, or alternatively you could keep Do While and delete Else and Loop from the end.

Hope this helps

Someone please correct me if I'm wrong there, I don't use Do - Loop as a rule so not 100% certain on this.
 
Upvote 0

Forum statistics

Threads
1,214,394
Messages
6,119,263
Members
448,881
Latest member
Faxgirl

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