For Each Loop - Strange BehaviourI have a list of names and use the FOR EACH Loop to check if a worksheet exists in the workbook with the same. It works perfectly up to the point where such a worksheet actually exists, it indicates that this worksheet does indeed exist. However, after this point it erroneously indicates the existence of worksheets with the remainder of the names in the list.For example I have a list with the following names: "Name1", "Name2", "Name3", "Name4", "Name5", "Name6", and "Name7". The workbook contains sheets with the names "Name4" and "Name7". The code is suppose to indicate whether sheets with names , "Name1", "Name2", "Name3", "Name4", "Name5", "Name6", and "Name7" exist in the workbook. It does exactly that untill it encounters the name "Name4" in the list. It correctly indicates that sheet "Name4" does indeed exist, but then continue indicating that the sheets "Name5" and "Name6" also exist, which in this case does not.I would appreciate an understanding of this behaviour and how the code should be changed to achieve the intended results.Note: Should the code end up in one line I would appreciate some assistance in correcting it, I have tried everything and every time it ends up in one long line (holding thumbs)!Regards,vanhunk
Sub VerifyCurrentList() 'Verify that the proposed sheet name does not already exist in the workbook:'------------------------------------------------------------------------------ Dim strContractor As String Dim wks As Worksheet Dim bln As Boolean Dim oRange As Range Dim rCell As Range 'Define the search range: Set ws = Worksheets("Start Sheet") Set oRange = ws.Range(Range("ContractorsList").Offset(1, 0), Range("ContractorsList").Offset(30, 0).End(xlUp)) For Each rCell In oRange strContractor = rCell.Value 'MsgBox strContractor On Error Resume Next Set wks = ActiveWorkbook.Worksheets(strContractor) On Error Resume Next If Not wks Is Nothing Then bln = True Else bln = False Err.Clear End If If bln = False Then MsgBox strContractor & " is not current!" Else MsgBox strContractor & " is current!" End If Next rCell End Sub