vendredi 23 mars 2018

VBA: For/if/ElseIf

I got a problem concerning VBA in Excel. I have an userform, and if the user enters a entry that isnt already in the row, I want it to be added.

Range("D1:D1").Select

For i = 1 To 3000

  Zelle = "D" & i
  Range(Zelle).Select
  Wert = ActiveCell

  If Wert = "" Then
   Cells(Wert + 1, 4) = TB_prov
   Exit For
  ElseIf Wert = TB_prov Then
   Exit For
   Else
    Next i

End If
Exit For

I took an old code from the internet which helped me for a similar problem but I can't make it work here.

My intention was that the For-loop changes the active cell, and the if/elseif conditions check every cell. If the new entry is already existing, it stops. If the cell is empty, it puts the name is.

But it doenst work, but why? Thanks for help

Aucun commentaire:

Enregistrer un commentaire