Put Set rng = rng.Offset(1) after End If and before Next j so the row offsets for each j regardless if D is empty.

                rng.Offset(0, 12).Value = nodes(nd + 1).Attributes(1).Value
                
            End If
            Set rng = rng.Offset(1)
        Next j
    End With
Alternatively, offset the column .Values from rngCode as that is the current column D cell.