VBA Excel - Getting the value of the first column of a ListView

Anonymous
2023-11-08T22:00:55+00:00

Dear all,

by this line I'm getting the column x value of the ListView selected row.

Selected_ID = lvwShowUserLog.SelectedItem.ListSubItems(x).Text

The above code line works when x is not zero; in fact when I try to get the value of the first column (having index =0) of the selected row I get this error message:

With this line:

Selected_ID = lvwShowUserLog.SelectedItem.ListSubItems(0).Text

I should get the ID value which is 1: I’m doing something wrong?

Thanks

Microsoft 365 and Office | Excel | Other | 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
Answer accepted by question author
  1. HansV 462.4K Reputation points MVP Volunteer Moderator
    2023-11-08T22:08:18+00:00

    ListSubItems, as the name indicates, contains only the subitems, i.e. column 1 and higher.

    To get the first column (column 0), use

    Selected_ID = lvwShowUserLog.SelectedItem.Text

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful