2
In Excel 2010, I need to go through a data table row by row and manipulate the data in VBA.
My original function reads like this:
Private Function GetValue(ByVal myRange As Excel.Range, ByVal strCol As String) As String
Dim myCell As Object
Set myCell = myRange.Cells(, strCol)
GetValue = myCell.Value
End Function
I call it like this:
GetValue(myRow, "AE")
myRow
is an Excel.Range representing a row.
"AE"
is the column index.
I want to convert to use column names instead of column indexes because users may choose to add or remove columns in the future. I identified a range of cells as a table in Excel, named the table, and chose unique column names.
This means I would now call the function by using:
GetValue(myRow, "column_name")
but I can't find examples where I can specify only the column name without also specifying the row.
Is this even feasible?
If you don't want to specify the row, how will Excel/VBA know what row you're trying to manipulate? – misha256 – 2015-02-09T22:49:44.033
Because I'm passing the row as a parameter to the function. – chabzjo – 2015-02-10T19:48:28.907