Share via

naming using column numbers - can't do it!

Anonymous
2025-02-27T15:06:01+00:00

In MS Excel VBA, I need to refer to a cell/range using the column number, not the column letter, and i want to do that using a variable that i can then loop to increase by 2 each time. I am seriously struggling to work out the correct syntax for referring to a cell/range in this way - i am continuously getting error message and i suspect it's cos i'm using "" and () slightly wrong. can anyone help while i still have some hair left to pull out?

i'm sure this is simple but it's driving me mad

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. HansV 462.6K Reputation points
    2025-02-27T15:15:04+00:00

    Use Cells(row_number, column_number).

    For example, cell D2 (2nd row, 4th column) is Cells(2, 4)

        Dim c As Long
        For c = 1 To 15 Step 2
            Cells(2, c).Value = c
        Next c
    

    Was this answer helpful?

    0 comments No comments