Excel complete formula depends on the cell is filled or not otherwise use other cell

dear experts,

could anybody help me with this one. I like to fill this command below depending on Excel-Cells. So far so good.
The formula should check if the cell C9 has a value (email adress) and if not use CELL C8 to complete the
command. If C9 has a value use this if not use C8

Thanks in advance

CELL C8 test@test.com
CELL C9 jones@gal.com

="Set-Mailbox -EmailAddresses 'SMTP:"&C8&"' -SingleItemRecoveryEnabled $true -EmailAddressPolicyEnabled $false -Displayname '"&B5&"'

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ejgil HedegaardCommented:
Use IF(LEN(C9),C9,C8) for C8 in the formula, like this
="Set-Mailbox -EmailAddresses 'SMTP:"&IF(LEN(C9),C9,C8)&"' -SingleItemRecoveryEnabled $true -EmailAddressPolicyEnabled $false -Displayname '"&B5&"'"

Open in new window

Mandy_Author Commented:
Thanks. I'm getting #name?
Mandy_Author Commented:

if i use the string below i'm getting   #name?
I dont know what is wrong

="Set-Mailbox -identity "jones, robert" -EmailAddresses 'SMTP:"&IF(LEN(C9),C9,C8)&"'"
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Ejgil HedegaardCommented:
jones, robert is between the 2 texts "Set-Mailbox -identity " and " -EmailAddresses 'SMTP:" without & to join.
It should be
="Set-Mailbox -identity "&"jones, robert"&" -EmailAddresses 'SMTP:"&IF(LEN(C9),C9,C8)&"'"
="Set-Mailbox -identity jones, robert -EmailAddresses 'SMTP:"&IF(LEN(C9),C9,C8)&"'"

Strange you can enter it.
Mandy_Author Commented:
Still the same. #name?
to join the name is not needed. I put the formula  ="Set-Mailbox -EmailAddresses 'SMTP:"&IF(LEN(C9),C9,C8)&"'"
in cell C10 and it should resolve from the CELL C9 (123@test.com) like 'SMTP:123@test.com‘ or if the CELL C9 is
empty from Cell C8. The result should be  

Set-Mailbox -EmailAddresses 'SMTP:123@test.com‘     or Set-Mailbox -EmailAddresses SMTP:456@test.com‘
if the cell C9 is empty and C8 is 456@test.com.
Ejgil HedegaardCommented:
The error #name? means Excel can't recognise the used function, and 'think' it is a named range, and that name don't exist.
Are you using an English version of Excel?

Try typing the formula =IF(LEN(C9),C9,C8) in an empty cell.
When you type =i a list with available functions starting with i are shown, and if IF is not on the list, that is the problem.
Ejgil HedegaardCommented:
See sheet with the formula.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mandy_Author Commented:
thank you so much
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.