I'll try and be as clear as possible. The nested loops is meant to go through the InTbl's amended column and look for find any cell that has a value in.
It's also then meant to loop through each row of the asset codes table through list column two (specifically for the asset code) and check it against the asset code in the input table (with row reference i)
Once it finds the row with the asset code matching reference i, it should post the value from the amended column into the cell offset from the cell in the Asset table.
The main issue I am getting is that none of the values are being copied over, I think there is something wrong in the piece of code
For c = 1 To LastAss
If AsTbl.DataBodyRange(c, 2).Value = InTbl.DataBodyRange(i, 4).Value Then
AsTbl.DataBodyRange(c, 2).Offset(0, 6).Value = InTbl.DataBodyRange(1, 4).Value
End If
Next
But I can't actually tell which bit is wrong.
Anyways, please find my code below, is there any ideas? or should it be done differently?
Dim InTbl As ListObject, i As Long, LastRow As Long, AmendedCCY, AsTbl As ListObject, c As Long, AssCode As Range, LastAss As Long 'Defines all variables
Set InTbl = ThisWorkbook.Sheets("Input").Range("Input").ListObject ' Sets inTbl as the input table's data without headings
Set AmendedCCY = InTbl.ListColumns(4).DataBodyRange ' Sets variable as spcifically the amended column in the input table
Set AsTbl = ThisWorkbook.Sheets("Asset List").Range("AssListTab").ListObject 'Sets variable as the full asset table
Set AssCode = AsTbl.ListColumns(2).DataBodyRange
LastRow = AmendedCCY.Rows.Count 'Sets variable as the number of rows in the data range of the input table (or as the number of assets)
LastAss = AssCode.Rows.Count
For i = 1 To LastRow 'For each iteration from one to the number of all rows.
If Not IsEmpty(InTbl.DataBodyRange(i, 4).Value) Then 'If the cell in the amended column is not empty then
For c = 1 To LastAss
If AsTbl.DataBodyRange(c, 2).Value = InTbl.DataBodyRange(i, 4).Value Then
AsTbl.DataBodyRange(c, 2).Offset(0, 6).Value = InTbl.DataBodyRange(1, 4).Value
End If
Next
End If
Next 'Go to next iteration
End Sub