Hi - I have a table that gets updated with new data in columns D-F utilising a flow.
I then need to populate formulas in columns G-N from the first blank cell in column G to the last row of the table (based on data in column D).
The formulas are look ups to another sheet that is downloaded from an external system and copied and pasted into sheet 2 named MCAP Supplier Console. This data changes so old values disappear as such I can't just apply formulas to all columns as that will cause older records to pull through as N/A and so I am currently copying all data and pasting as values after using the formulas to pull the new data through.
I have tried a number of ways to populate cells with the formulas but after hours of searching for help I am really struggling to find how to select the first blank entry in column G and populate the formulas down to the last table entry.
At the moment I have been doing this manually by just hovering over bottom right of cell and double clicking to fill down but I would like this to be a step undertaken by the macro so anyone in my team could complete the task by just pressing one command button.
My code is currently this which works to populate the formula but only in a set range so any help on how to amend the code to set the range to the blank columns in the new rows only.
Sub Test2()
Dim strFormulas(1 To 8) As Variant
With ThisWorkbook.Sheets("POs Received")
strFormulas(1) = "=INDEX('MCAP Supplier Console'!A:U,(MATCH([@[PO number]],'MCAP Supplier Console'!J:J,0)),12)"
strFormulas(2) = "=INDEX('MCAP Supplier Console'!A:U,(MATCH([@[PO number]],'MCAP Supplier Console'!J:J,0)),5)"
strFormulas(3) = "=INDEX('MCAP Supplier Console'!A:U,(MATCH([@[PO number]],'MCAP Supplier Console'!J:J,0)),6)"
strFormulas(4) = "=INDEX('MCAP Supplier Console'!A:U,(MATCH([@[PO number]],'MCAP Supplier Console'!J:J,0)),1)"
strFormulas(5) = "=INDEX('MCAP Supplier Console'!A:U,(MATCH([@[PO number]],'MCAP Supplier Console'!J:J,0)),16)"
strFormulas(6) = "=INDEX('MCAP Supplier Console'!A:U,(MATCH([@[PO number]],'MCAP Supplier Console'!J:J,0)),13)"
strFormulas(7) = "=INDEX('MCAP Supplier Console'!A:U,(MATCH([@[PO number]],'MCAP Supplier Console'!J:J,0)),8)"
strFormulas(8) = "=INDEX('MCAP Supplier Console'!A:U,(MATCH([@[PO number]],'MCAP Supplier Console'!J:J,0)),9)"
.Range("g5644:n5644").Formula = strFormulas
.Range("g5644:n5660").FillDown
End With
End Sub
I then need to populate formulas in columns G-N from the first blank cell in column G to the last row of the table (based on data in column D).
The formulas are look ups to another sheet that is downloaded from an external system and copied and pasted into sheet 2 named MCAP Supplier Console. This data changes so old values disappear as such I can't just apply formulas to all columns as that will cause older records to pull through as N/A and so I am currently copying all data and pasting as values after using the formulas to pull the new data through.
I have tried a number of ways to populate cells with the formulas but after hours of searching for help I am really struggling to find how to select the first blank entry in column G and populate the formulas down to the last table entry.
At the moment I have been doing this manually by just hovering over bottom right of cell and double clicking to fill down but I would like this to be a step undertaken by the macro so anyone in my team could complete the task by just pressing one command button.
My code is currently this which works to populate the formula but only in a set range so any help on how to amend the code to set the range to the blank columns in the new rows only.
Sub Test2()
Dim strFormulas(1 To 8) As Variant
With ThisWorkbook.Sheets("POs Received")
strFormulas(1) = "=INDEX('MCAP Supplier Console'!A:U,(MATCH([@[PO number]],'MCAP Supplier Console'!J:J,0)),12)"
strFormulas(2) = "=INDEX('MCAP Supplier Console'!A:U,(MATCH([@[PO number]],'MCAP Supplier Console'!J:J,0)),5)"
strFormulas(3) = "=INDEX('MCAP Supplier Console'!A:U,(MATCH([@[PO number]],'MCAP Supplier Console'!J:J,0)),6)"
strFormulas(4) = "=INDEX('MCAP Supplier Console'!A:U,(MATCH([@[PO number]],'MCAP Supplier Console'!J:J,0)),1)"
strFormulas(5) = "=INDEX('MCAP Supplier Console'!A:U,(MATCH([@[PO number]],'MCAP Supplier Console'!J:J,0)),16)"
strFormulas(6) = "=INDEX('MCAP Supplier Console'!A:U,(MATCH([@[PO number]],'MCAP Supplier Console'!J:J,0)),13)"
strFormulas(7) = "=INDEX('MCAP Supplier Console'!A:U,(MATCH([@[PO number]],'MCAP Supplier Console'!J:J,0)),8)"
strFormulas(8) = "=INDEX('MCAP Supplier Console'!A:U,(MATCH([@[PO number]],'MCAP Supplier Console'!J:J,0)),9)"
.Range("g5644:n5644").Formula = strFormulas
.Range("g5644:n5660").FillDown
End With
End Sub