S Karthi Keyan
S Karthi Keyan

Reputation: 3

Is this syntax is correct?

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

IMG1

Upvotes: 0

Views: 45

Answers (1)

Michał Turczyn
Michał Turczyn

Reputation: 37500

Your syntax is generally ok, but I would like to point out some risks and issues with it:

  1. 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:

  2. Always declare your variables, like this: Dim a As Long, j As Long, k As Long.

  3. 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

Related Questions