Predmet:sto je najbrze for next , for each ili match
sto bi vi koristili u svojem VBA kodu
treba naci string "jabuka" u koloni A
PreuzmiIzvorni kôd (Visual Basic):Sub test()
Dim traziString As String
Dim zadnjiRed As Long
Dim nadeniRed As Long
traziString = "jabuka" 'string koji se trazi
zadnjiRed = Cells(Rows.Count, "A").End(xlUp).Row 'trazi zadnji red u koloni A
'FOR EACH
For Each cell In Range("A1:A" & zadnjiRed) 'pocinje od A1
If cell.Value = traziString Then
nadeniRed = cell.Row
End If
Next cell
MsgBox nadeniRed
nadeniRed = 0'resetiram na nulu
'FOR NEXT
For f = 1 To zadnjiRed
If Cells(f, 1) = traziString Then
nadeniRed = f
End If
Next f
MsgBox nadeniRed
nadeniRed = 0'resetiram na nulu
'MATCH
On Error Resume Next
nadeniRed = Application.WorksheetFunction.Match(traziString, Range("A1:A" & zadnjiRed), 0)
On Error GoTo 0
If nadeniRed > 0 Then
MsgBox nadeniRed
End If
End Sub
zivot je moja domovina.