|
-
Jun 8th, 2005, 06:50 PM
#1
Thread Starter
Member
Exiting a Loop [Resolved]
Hello all,
I have a loop which i want to skip to the next i if a condition is meet how do i do this. My code is.
VB Code:
For i = 2 To 16
x = i + 1
EmployeeName = Sheets("Summary").Cells(i, 1)
EmployeeNum = Sheets("Summary").Cells(i, 2)
EmployeeNumEnd = Sheets("Summary").Cells(x, 2)
Sheets(EmployeeName).Select
Columns("A:J").Select
Selection.ClearContents
If EmployeeNum = 0 Then
Next i
End If
If EmployeeNumEnd = 0 Then
x = i + 2
EmployeeNumEnd = Sheets("Summary").Cells(x, 2)
End If
ActiveWorkbook.Sheets("Import").Select
y = EmployeeNumEnd - 1
Rows(EmployeeNum & ":" & y).Select
Selection.Cut
Sheets(EmployeeName).Select
Range("A3").Select
ActiveSheet.Paste
Range("A1") = DateReport
Range("A2:J2") = Heading
Range("A1").Select
Next i
The problem i'm having is in the first IF statment is says that the Next i is not matched with and for statment. How can do what i'm trying to achieve.
Any help would be greatly appreicated.
Regards,
Pearso
Last edited by Pearso; Jun 9th, 2005 at 06:15 PM.
-
Jun 8th, 2005, 09:07 PM
#2
Frenzied Member
Re: Exiting a Loop
I may be getting my languages mixed up here, but look up Break & Continue.
Tengo mas preguntas que contestas
-
Jun 8th, 2005, 09:26 PM
#3
Thread Starter
Member
Re: Exiting a Loop
Thanks for the suggestion but i had no luck find anything that would help.
If anyone else has any ideas it would be greatly appreicated.
-
Jun 8th, 2005, 10:59 PM
#4
Re: Exiting a Loop
You can do it like this...
VB Code:
For i = 2 To 16
x = i + 1
EmployeeName = Sheets("Summary").Cells(i, 1)
EmployeeNum = Sheets("Summary").Cells(i, 2)
EmployeeNumEnd = Sheets("Summary").Cells(x, 2)
Sheets(EmployeeName).Select
Columns("A:J").Select
Selection.ClearContents
If EmployeeNum = 0 Then
'Next i
Else
If EmployeeNumEnd = 0 Then
x = i + 2
EmployeeNumEnd = Sheets("Summary").Cells(x, 2)
End If
ActiveWorkbook.Sheets("Import").Select
y = EmployeeNumEnd - 1
Rows(EmployeeNum & ":" & y).Select
Selection.Cut
Sheets(EmployeeName).Select
Range("A3").Select
ActiveSheet.Paste
Range("A1") = DateReport
Range("A2:J2") = Heading
Range("A1").Select
End If
Next i
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 9th, 2005, 06:14 PM
#5
Thread Starter
Member
Re: Exiting a Loop
The solution was that easy,
Thanks for the help..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|