Automatically fill columns with formula with conditions

I have columns in an Excel sheet that I would like to automatically fill with a formula.

The VBA code I currently have is:
Range("M3") = "=J3&"" & ""&K3": Range("M3:M" & lRow).FillDown

However, column K contains the spouse's name if they have one, which means sometimes the cell in column K is blank.  If the person doesn't have a spouse, column M then reads:
First Name (from column J) &.

I've tried the following code but it causes an error:
Range("M3") = IF(Len(K3)=),"=J3&","=J3&"" & ""&K3": Range("M3:M" & lRow).FillDown

Any suggestions?
Thanks in advance.
Jeffrey VogelzangAsked:
Who is Participating?
Subodh Tiwari (Neeraj)Connect With a Mentor Excel & VBA ExpertCommented:
All you need is this...

Range("M3:M" & lRow).Formula = "=IF(K3="""",J3,J3&"" & ""&K3)"

Open in new window

Jeffrey VogelzangAuthor Commented:
Thank you for a quick and correct answer. Not sure why I didn't think of that, but...
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome Jeffrey! Glad I could help.
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.

All Courses

From novice to tech pro — start learning today.