I\'m currently working on a data set which is formatted as a table, with headers. What I need to do is cycle through all cells in a specific column and change the contents.
Since none of the above answers helped me with my problem, here my solution to extract a certain (named) column from each row.
I convert a table into text using the values of some named columns (Yes
, No
, Maybe
) within the named Excel table myTable
on the tab mySheet
using the following (Excel) VBA snippet:
Function Table2text()
Dim NumRows, i As Integer
Dim rngTab As Range
Set rngTab = ThisWorkbook.Worksheets("mySheet").Range("myTable")
' For each row, convert the named columns into an enumeration
For i = 1 To rngTab.Rows.Count
Table2text= Table2text & "- Yes:" & Range("myTable[Yes]")(i).Value & Chr(10)
Table2text= Table2text & "- No: " & Range("myTable[No]")(i).Value & Chr(10)
Table2text= Table2text & "- Maybe: "& Range("myTable[Maybe]")(i).Value & Chr(10) & Chr(10)
Next i
' Finalize return value
Table2text = Table2text & Chr(10)
End Function
We define a range rngTab
over which we loop. The trick is to use Range("myTable[col]")(i)
to extract the entry of column col
in row i
.