SkywardPalm
Board Regular
- Joined
- Oct 23, 2021
- Messages
- 61
- Office Version
- 365
- Platform
- Windows
I am trying to fill the blank within a table with found data from a second table using VBA. It works, but after the first column is found and filled with data the next columns take much longer (about a minute each) to fill. If there is a better method please let me know, I have tried VLOOKUP/XLOOKUP/INDEX&MATCH and all seem to be slower than they could be. I'm working with 300k rows in each table (max), but it's meant to scale to any size table.
Here is the snippet of code I am working with..
Here is the snippet of code I am working with..
VBA Code:
For Each rColHead In rActiveColHeaders
Set foundCol = rReferenceColHeaders.Find(rColHead.Value)
If Not foundCol = "ID" Then
If Not foundCol Is Nothing Then
'Takes too long after first found Header..
With wksTempData.ListObjects("tempTable1").ListColumns(rColHead.Value).DataBodyRange
On Error Resume Next 'ignore error if no blanks
Set blankRng = .SpecialCells(xlCellTypeBlanks)
If Not blankRng Is Nothing Then blankRng.Value = _
"=XLOOKUP([@ID],tempTable2[ID],tempTable2[" & rColHead & "],0)"
' If Not blankRng Is Nothing Then blankRng.Value = _
"=INDEX(tempTable2,MATCH([@ID],tempTable2[ID],0),MATCH(""" & rColHead & """,tempTable2[#Headers],0))"
' If Not blankRng Is Nothing Then blankRng.Value = _
"=VLOOKUP([@ID],tempTable2,MATCH(""" & rColHead & """,tempTable2[#Headers],0),0)"
End With
Else
Debug.Print rColHead.Value & " was not found. "
End If
End If
Next rColHead