Reputation: 3
a = 2
k = 35
j = 3
For Each Cell In Range(Cells((k + 1), j), Cells((k + 1), (a + (j - 1))))
If ActiveSheet.Cells(k, (j + 1)).Value = a Then
Cell.Value = m
Else
Cell.Value = Sheets("LAP " & (a - 1)).Cells((k + 1), j).Value
End If
Next Cell
Upvotes: 0
Views: 45
Reputation: 37500
Your syntax is generally ok, but I would like to point out some risks and issues with it:
Always use Option Explicit
: while not useful at first, it can save you lot of headache in the future. It makes you declare your variables before using them, which lead us to:
Always declare your variables, like this: Dim a As Long, j As Long, k As Long
.
As your loop variable, you use Cell
, the name is meaningful and good, but VBA might reserve that name for some other purpose and it will lead to a name conflict.
Upvotes: 1