Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 148
  • Last Modified:

Go to the next record

In the below I want to go to the next worksheet if the condition is not met..The only way I could figure this out was by doing GOTO..What is a suggestion

For each ws in this workbook
  If ws.Range ("A2") Like "2013" Then
    GOTO Next
  else
  code line
  code line
  code line
 code line
NEXT:
Next ws
 code line
 code line
 code line
 code line

End Sub
0
upobDaPlaya
Asked:
upobDaPlaya
  • 3
  • 2
1 Solution
 
nutschCommented:
How about:

For Each ws In ActiveWorkbook.Worksheets

  If Not ws.range("A2") Like 2013 Then
    ' Code Line
    ' Code Line
    ' Code Line
    ' Code Line
  End If
  
Next ws
'
' Code Line
' Code Line
' Code Line
' Code Line

Open in new window

0
 
upobDaPlayaAuthor Commented:
If it does not meet the criteria I do not want it to execute the code after the Next WS line...if the condition is not met I need it to go to then next worksheet
0
 
nutschCommented:
That's why it says: if <b>not</b> ... Like
0
 
nutschCommented:
So the code I've put does this

For each worksheet in workbook
If not condition then
Do stuff
End if
Next worksheet

Do more stuff at the end
0
 
upobDaPlayaAuthor Commented:
Got it...did not see the NOT :)   thx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now