loop inside a loop (I don't want it to exit)

cazdealer

Board Regular
Joined
Mar 12, 2011
Messages
96
Hi, I'm not that good with VBA but I've managed to do a procedure that is pretty complex (for me). I'm stuck right now with something it does.
I have a list of symbols in worksheet "orders" from A2 to A1000 for exemple.
I have this code below that create a sheet named like my symbols if I doesnt exist.

The problem is that as soon it finds a worksheet that is already named like my symbol, the procedure stops (which I don't want it to)...

for exemple..
if
A2 = C
A3 = BAC
A4 = GS
A5 = IBM
A5 = IBM
A6 = AAPL
A7 = YHOO

my macro will create a sheet named, C, BAC, IBM but will stops there (because there will already by a IBM sheets after the macro have created one from A5)...

How could I change my procedure for it to continue to A7 and also create a AAPL and YHOO sheets?




Code:
Sub createlistworksheets()


Dim i As Integer
Dim z As Integer
Dim k As String
Dim y As Integer, blnFound As Boolean
    blnFound = False



i = 2
z = Worksheets("orders").Cells(Rows.Count, "A").End(xlUp).Row


For i = 2 To z


k = Worksheets("orders").Cells(i, 1).Value


With thisworkbook


        For y = 1 To .Sheets.Count
            If .Sheets(y).Name = k Then
                blnFound = True
                Exit For
            End If
        Next y
        
        If blnFound = False Then
            .Sheets.Add
            With ActiveSheet
                .Name = k
            End With
        End If
    End With

  
    k = 0
  
    Next i
    
End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
cazdealer,

You just need to reset blnFound to False. Either here

Code:
blnFound = False
Next i

or here

Code:
For i = 2 To z
blnFound = False
 
Upvote 0

Forum statistics

Threads
1,224,507
Messages
6,179,181
Members
452,893
Latest member
denay

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