2

Ok, probably an easy one but I'm just starting to use this language and in this piece of code :

While DATA.Cells(1, i).value & "" <> ""
    If InStr(DATA.Cells(1, i).value, columnName) > 0 Then
        column = i
        Exit While
    End If
    i = i + 1
Wend

It looks like it's not the way to use Exit While ? How should I do it then ?

Ellone
  • 3,644
  • 12
  • 40
  • 72

1 Answers1

2

A While/Wend can only be exited prematurely with a GOTO or by exiting from an outer block (Exit sub/function/another exitable loop)

Change to a Do loop intead

Do While DATA.Cells(1, i).value & "" <> ""
If InStr(DATA.Cells(1, i).value, columnName) > 0 Then
    column = i
    Exit Do
End If
i = i + 1
Loop

Original answer from @Alex K. Break out of a While...Wend loop in VBA

Community
  • 1
  • 1
KodornaRocks
  • 425
  • 3
  • 14