View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
ChadF ChadF is offline
external usenet poster
 
Posts: 44
Default Nesting For loops

I have a question about nested For-loop syntax...

In this function, I have a named range on my spreadsheet that has
'default' values called 'Select Company' ... Each of the cells defined
in that range - that's their starting value... The cells have a pull-down
list associated with them that allows the user to select a company from
a static list.

I'm trying to take advantage of the construct of the For-loop ...

For the outer loop, there are 3 'Next Outer' statements ... (2 inside
conditionals statements, 1 for the general For condition)

code looks like this...

Public Function BuildUniqueCompanyList() As Range

Dim CellIterOuter As Range
Dim CellIterInner As Range

Dim MyRange As Range ' This is the holder of unique values


For Each CellIterOuter In Range("Company_List")
If CellIterOuter.text = "<<Select Company" Then
Next CellIterOuter
End If

For Each CellIterInner In MyRange
If CellIterInner.text = CellIterOuter.text Then
Next CellIterOuter
End If
Next CellIterInner
MyRange.Insert (CellIterOuter) ' at this point, value is unique

Next CellIterOuter

BuildUniqueCompanyList = MyRange

End Function

What I want to do - the 'Next' statements that are wrapped inside
the IF-conditions return back to the outer loop construct instead of
continuing
with the next line of execution. The inner FOR-loop is pretty
straightforward; however, what I would like - if the logic encounters a
duplicate, stop the search
and break / continue with the Outer loop.

Is this possible to do in VBA ??

Appreciate any suggestions.

Thank you.
Chad