I want to execute if and in a loop.
The code runs when not in a loop. (When I run the code one by one it gives the result I want).
I use ActiveCell
as reference since I will use this code on another sheet with a different location.
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
The code for GetBaris
.
Function GetBaris() As Long
GetBaris = Range(ActiveCell.Offset(0, 1).Address, ActiveCell.Offset(0, 1).End(xlDown).Address).Rows.Count
End Function
The data and result of looping. First row is correct, but all the rest row should result in "Bukan Inv".