XLA routines: EE_GetColElements

Nick's picture
Use EE_GetColElements to get an range of column elements
Function EE_GetColElements(rngTableWithHeader As range, strColName As String) As Variant
    Dim intCol As Integer
    Dim rng As range
    Dim arr As Variant
    Dim arr2
'http://excelexperts.com/xla-routines-eeGetColElements    for updates on this function

    intCol = Application.WorksheetFunction.Match(strColName, rngTableWithHeader.Rows(1), 0)
    With rngTableWithHeader
        Set rng = Intersect(.Columns(intCol), .Columns(intCol).Offset(1))
        EE_GetColElements = rng
        If rngTableWithHeader.Rows.Count = 2 Then
            ReDim arrTemp(1 To 1, 1 To 1)
            arrTemp(1, 1) = rng.value
            EE_GetColElements = arrTemp
            EE_GetColElements = rng
        End If
    End With
End Function