Solved

Go to the next record

Posted on 2014-03-14
5
130 Views
Last Modified: 2014-03-15
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
Comment
Question by:upobDaPlaya
  • 3
  • 2
5 Comments
 
LVL 39

Accepted Solution

by:
nutsch earned 500 total points
ID: 39930862
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
 

Author Comment

by:upobDaPlaya
ID: 39930868
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
 
LVL 39

Expert Comment

by:nutsch
ID: 39930873
That's why it says: if <b>not</b> ... Like
0
 
LVL 39

Expert Comment

by:nutsch
ID: 39930876
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
 

Author Comment

by:upobDaPlaya
ID: 39930878
Got it...did not see the NOT :)   thx
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question