I have a problem when executing vba code for if and in a loop.
The code runs well when it's not in a loop (when I run the code one by one it give the result I want). I use ActiveCell as reference since I will use this code on another sheet with different location.
Here I attach the code and picture of data, thanks in advance.
Sub cobalagi()
Dim a, b As Range
Set a = ActiveCell.Offset(0, 3)
Set b = ActiveCell.Offset(0, 4)
For I = 1 To GetBaris
If Left(a.Value, 8) = "KML/INV/" And b.Value = "Project - cost" Then
ActiveCell.Value = "Inv"
Else
ActiveCell.Value = "Bukan Inv"
End If
ActiveCell.Offset(1, 0).Select
Next I
End Sub
bellow the code for GetBaris (even tho I think nothings wrong with this code)
Function GetBaris() As Long
GetBaris = Range(ActiveCell.Offset(0, 1).Address, ActiveCell.Offset(0, 1).End(xlDown).Address).Rows.Count
End Function