# VBA ListColumns index number



## DomioGeordio (Dec 19, 2022)

I am struggling to work out how to get the index number of a table column in VBA. I have tried various forms of ActiveWorkbooks.Sheets("sheet2").ListObjects("table1").ListColumns("column3").index and whatnot but nothing seems to work. I can get the column name if I have the index number but cannot seem to go the other way round and get the index number from the Column name. When I check the Locals I can see that both pieces of info are available and I am sure I am missing something obvious. Any help would be greatly appreciated


----------



## Domenic (Dec 19, 2022)

You almost have it.  You've added an 's' to ActiveWorkbook.  It should be...


```
ActiveWorkbook.Sheets("sheet2").ListObjects("table1").ListColumns("column3").index
```

Hope this helps!


----------



## DomioGeordio (Dec 20, 2022)

I still get the "Object does not support this property or method"

This shouldn't be so difficult!


----------



## Alex Blakenburg (Dec 20, 2022)

Did you put something on the other end of that line ?
If you don't do something with it you will get that error message.


```
Sub test()

    Dim colIdx As Long
    *colIdx = *ActiveWorkbook.Sheets("sheet2").ListObjects("table1").ListColumns("column3").Index
    Debug.Print colIdx

End Sub
```


----------



## DomioGeordio (Dec 20, 2022)

Alex Blakenburg said:


> Did you put something on the other end of that line ?
> If you don't do something with it you will get that error message.
> 
> 
> ...


That worked, weird that I tried to do it in a msgbox to see and it didn't work at all but when I use it in a variable it does. Means slightly longer code than I wanted but at least it works! Thank you for that


----------



## Alex Blakenburg (Dec 20, 2022)

If you meant something like this, it worked for me:

```
MsgBox "Column Index No is: " & ActiveWorkbook.Sheets("sheet2").ListObjects("table1").ListColumns("column3").Index
```


----------

