The following formula (in $G$2 and completed) should do the trick:
=IF(ISBLANK(F2),"xxx",INDEX(B2:E2,,COUNTBLANK(B2:F2)+1))
Note that this will only work if there are no other empty cells between the first and last cells.
update: Below is a more universal version from Mr.Excel forum :
=INDEX(B2:F2,MATCH(1,IF(B2:F2<>0,IF(B2:F2<>"",1)),0))
This should be entered as an "array formula", which means you must press CTRL-SHIFT-ENTER after pasting into the formula.
response to comment:
It works fine, except if all cells are empty in the row, it returns # N / A. So, I slightly modified the formula to include the IsNA () condition:
=IF(ISNA(INDEX(B2:F2,MATCH(1,IF(B2:F2<>0,IF(B2:F2<>"",1)),0))), "xxx", INDEX(B2:F2,MATCH(1,IF(B2:F2<>0,IF(B2:F2<>"",1)),0)))
Instead of duplicating the whole formula, you can do the following:
=IF(COUNTBLANK(B2:F2)=COLUMNS(B2:F2),"xxx", INDEX(B2:F2,MATCH(1,IF(B2:F2<>0,IF(B2:F2<>"",1)),0)))