VBA: Referring to current row in Excel Table

Anonymous
2023-11-28T21:37:43+00:00

Good Morning

I'm trying to refer to the current row in a table but whatever I try, nothing works. I understand that the table model doesn't have a direct route to the information.

My issue is that whatever I plug in here, the result for ListRow is 0.

Dim r As Long

r = ActiveCell.row

Dim tableRow As Long

tableRow = tblCustomer.HeaderRowRange.row

Dim ListRow As Long

ListRow = ActiveCell.row - tableRow

It's too weird because on my last run

  • r = 5
  • ActiveCell.row = 10
  • tableRow = 5
  • tblCustomer.HeaderRowRange.row = 6

So if I plug in numbers into above code, it would read like this:

r = ActiveCell.row

5 = 10

tableRow = tblCustomer.HeaderRowRange.row

5 = 6

ListRow = ActiveCell.row - tableRow

0 = 10 = 5

What is going on?

Does anybody know how to solve this?

Thanks,

Christine

Microsoft 365 and Office | Excel | For business | 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
{count} votes

3 answers

Sort by: Most helpful
  1. Anonymous
    2023-11-29T03:23:24+00:00

    What do you want to do next?
    r=10

    TableRow=6

    ListRow=4

    0 comments No comments
  2. Anonymous
    2023-11-29T03:41:21+00:00

    Good question. It's not the result was getting. I get the right result now but I'm not quite sure I can trust it ...

    I think I have to revert my code back to absolute rather than table references and keep adjusting for any changes.

    Thanks for confirming that I'm not going mad.

    0 comments No comments
  3. Anonymous
    2023-11-29T05:11:59+00:00

    You are welcome. Feel free to share any update:)

    0 comments No comments