idlewyld89
New Member
- Joined
- Jun 10, 2018
- Messages
- 23
I'm developing an excel application for a variety of users, and as a result several routines require the adaptability to test the location of several key columns of data. The goal with this small function is to identify the column index of a specified column via the header value.
By assigning static values, this function works 100% as intended. However, I am having trouble with the syntax of passing several of the values as dynamic variables.
Here is the basic premise:
Where Wrkbk is previously defined as a workbook requested of the user and stored as a workbook object, TableName is just hard-coded as a value (typically static, but referenced elsewhere... just wanted it to be easy to update at a later time if necessary) and Criteria is also defined previously as an array and incremented through in a separate sub.
Therefore, the call would be approximately:
Again, to be clear, GMDirectory is previously defined as a Workbook object (global variable) and ColumnNames(i) is an array of length 3 that is looped through to UBOUND in order to VLOOKUP against the users directory.
Any assistance would be greatly appreciated, as I've been somewhat stumped on this. Have found several useful sites that reference the general structure when working with tables, but none have examples of introducing parameters as variables.
By assigning static values, this function works 100% as intended. However, I am having trouble with the syntax of passing several of the values as dynamic variables.
Here is the basic premise:
Code:
Private Function ReturnHeaderIndex(ByVal Wrkbk As Workbook, ByVal TableName As String, ByVal Criteria As String) As Integer' References:
' Dependents:
' ~~>
ReturnHeaderIndex = Wrkbk.ListObject("TableName[Criteria]").Column
End Function
Where Wrkbk is previously defined as a workbook requested of the user and stored as a workbook object, TableName is just hard-coded as a value (typically static, but referenced elsewhere... just wanted it to be easy to update at a later time if necessary) and Criteria is also defined previously as an array and incremented through in a separate sub.
Therefore, the call would be approximately:
Code:
ReturnHeaderIndex(GMDirectory, "Directory", ColumnNames(i))
Again, to be clear, GMDirectory is previously defined as a Workbook object (global variable) and ColumnNames(i) is an array of length 3 that is looped through to UBOUND in order to VLOOKUP against the users directory.
Any assistance would be greatly appreciated, as I've been somewhat stumped on this. Have found several useful sites that reference the general structure when working with tables, but none have examples of introducing parameters as variables.