Selected Answer
I placed the column captions in range A2:F2 and the numbers below that in range A3:F5. (I added the horse to have a column without a 9 in it.) Then I wrote the variable in G1 as you have suggested. Now I placed my formula in A7 and copied it from there to B7:F7
=IF(ISNA(MATCH($G$1,A$3:A$5,0)),"",A$2)
Now, as you change the referenced number in G1 you will observe different lists in row 7.
That is the easy part. Its advantage is that you can add as many columns and rows of numbers as you may desire. However, you appear to want the result arranged vertically in column G and I suspect that you will want to do away with the unavoidable blanks before you are done wishing for improvements. I estimated that a formula to do all that would be about 16 times the size of the above one which would make it about 64 times more complicated.
Therefore I added VBA to the attached workbook. You will find the code in the code module for sheet "MatchCaptions". (Press Alt+F11 to access the VB Editor.) Read the comments. There are lots of things you can modify to better match your requirements. The code runs whenever you change G1.