Jugulator
8/12/2018 - 11:02 AM

Write RecordSet Column To Range

Dependency: CopyRecordsetColumnToArray

Sub WriteRecordSetColumnToRange(ByVal adoRecSet As ADODB.Recordset, ByVal columnName As String, ByVal startCell As Range)
'Description:   Writes one field(column) of a Recordset to a Range
'Input:         Recordset object; ; name of the field(column); start cell (Range)
'Dependency:    CopyRecordsetColumnToArray 

'******   DEKLARÁCIÓK   ********************
Dim tempArr     As Variant
Dim tempRng     As Range
'*******************************************

'   if startCell consists of more then one cell then upper-left cell is used
    If startCell.Cells.Count > 1 Then startCell = startCell.Cells(1)
    
'   Save column to Array
    tempArr = CopyRecordsetColumnToArray(adoRecSet, columnName)
    
'   Resize Range then write Array to Range
    Set tempRng = startCell.Resize(UBound(tempArr, 1) + 1, 1)
    tempRng.Value = tempArr
        

End Sub