Low performance when adding values to a listobject in VBA

Viewed 102

I need to print a large amount of data to a listobject, and the function I have written works, but is extremely slow:

Public Sub PrintCollectionToTableByHeaderName(tb As ListObject, values As Collection, keylist as Collection, Optional rownum As Long, Optional alreadyvalidated As Boolean)
Dim i As Integer
    If TbColsAreValid(tb, keylist, alreadyvalidated) Then
        If Not rownum <> 0 Then: rownum = tb.ListRows.count + 1
        For i = 1 To keylist.count
            tb.ListColumns(keylist(i)).DataBodyRange(rownum, 1).value = values(keylist(i))
        Next i
    Else
        MsgBox "Err: Headers Not Valid"
    End If
End Sub

Would anyone be able to suggest a more efficient way of doing this?

0 Answers
Related