I am trying to increase the integer variable by 1 in a for each loop. I am either getting a value of 1 or a value of total count, but not an incremented value. Help please...
In this one, I always get a value of 1
Range("G2").Select
Dim counter As Integer
Dim N As String
Set myrange = Range(Selection, Selection.End(xlDown))
counter = 1
For Each MyCell In myrange.Cells
MyCell.FormulaR1C1 = "=IF(ISNA(INDEX(ALLITEMNAME,MATCH(RC[-6],ALLLABIN,0)))," & counter & ",(INDEX(ALLITEMNAME,MATCH(RC[-6],ALLLABIN,0))))"
counter = counter + 1
Next MyCell
In this one, I always get a value of 265 which is the total number of cells.
Dim rCell As Range
Dim rRng As Range
Dim counter As Integer
Dim nomatch As String
Dim Number As String
Set rRng = Range(Selection, Selection.End(xlDown))
counter = 1
nomatch = "No Match"
Number = "0"
For Each rCell In rRng.Cells
Number = Str(counter)
ActiveCell.FormulaR1C1 = "=IF(ISNA(INDEX(ALLITEMNAME,MATCH(RC[-6],ALLLABIN,0)))," & counter & ",(INDEX(ALLITEMNAME,MATCH(RC[-6],ALLLABIN,0))))"
counter = counter + 1
Next rCell
In this one, I always get a value of 1
Range("G2").Select
Dim counter As Integer
Dim N As String
Set myrange = Range(Selection, Selection.End(xlDown))
counter = 1
For Each MyCell In myrange.Cells
MyCell.FormulaR1C1 = "=IF(ISNA(INDEX(ALLITEMNAME,MATCH(RC[-6],ALLLABIN,0)))," & counter & ",(INDEX(ALLITEMNAME,MATCH(RC[-6],ALLLABIN,0))))"
counter = counter + 1
Next MyCell
In this one, I always get a value of 265 which is the total number of cells.
Dim rCell As Range
Dim rRng As Range
Dim counter As Integer
Dim nomatch As String
Dim Number As String
Set rRng = Range(Selection, Selection.End(xlDown))
counter = 1
nomatch = "No Match"
Number = "0"
For Each rCell In rRng.Cells
Number = Str(counter)
ActiveCell.FormulaR1C1 = "=IF(ISNA(INDEX(ALLITEMNAME,MATCH(RC[-6],ALLLABIN,0)))," & counter & ",(INDEX(ALLITEMNAME,MATCH(RC[-6],ALLLABIN,0))))"
counter = counter + 1
Next rCell