Search code examples
excelvba

vba : do something only on the first for each loop


for each element in sarray
  if ... then
     if this is the first time the above IF statenent was executed ... then
  end if
next element

i want to do something ONLY the first time that the first IF THEN statement is executed. i am having a lot of problems with my logic. please help!


Solution

  • var isExecuted = false
    for each element in sarray
      if ... then
         if Not isExecuted Then
            --do stuff
           isExecuted = true
         end if
      end if
    next element