How to match with a condition in Excel

Hello everyone.

Let’s assume we start from the following Excel document:
The rows whose background is blue can not be moved - the only ones that can be moved are those whose background is white.
What I would like to do is to avoid that names in the column C coincide with the names in the column F - for each group. For instance, “Name3” coincide in the first group, and “Name4” coincide in the second group, as we can see:


So the point is to move the white rows (in this case the rows 8 and 14 to other groups in such a way that the elements in the column G coincide for each group - at least as much as possible).

So the rows that must be moved are the following ones in yellow:


A possible solution for this problem could be:

I think first I should use “Read Range” C5:D7 and then E5:G8. Then I probably should use a for each row, checking that if some of the elements in the column F coincide with some of the elements in the column C. My problem comes now: i do not know how to operate so that the rows can be moved in such a way that the elements in column G still remain trying to be the same.

Exercise_.xlsx (9.1 KB)

I would really appreciate any help.

Thank you very very much,

Best regards.

No one?

Any help?