Macro to merge cells across columns based upon criteria

Hello experts,

I would like to have a macro that merges three columns based upon a set of criteria.

For instance, I have four columns of data, and for all rows with data in column A, if column D has data, but where also column B and C are blank, then merge column A with column B and column C.

Please find attached an example as a illustration.

Could anyone provide some assistance?

Regards

LK
EE-Example-Merge-Columns.xlsm
lkirkeAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Rgonzo1971Commented:
Hi,

pls try
Sub macro()
For Each c In Range(Range("A2"), Range("A" & Cells.Rows.Count).End(xlUp))
    If c.Offset(0, 3) <> "" Then
        c.Resize(1, 3).Merge
    End If
Next
End Sub

Open in new window

Regards
lkirkeAuthor Commented:
Hi Rgonzo,

Works great apart from the warning message for each merge. Is there a way to turn these off?
Rgonzo1971Commented:
Hi,

then try

Sub macro()
For Each c In Range(Range("A2"), Range("A" & Cells.Rows.Count).End(xlUp))
    If c.Offset(0, 3) <> "" Then
        Application.DisplayAlerts = False
        c.Resize(1, 3).Merge
        Application.DisplayAlerts = True
    End If
Next
End Sub

Open in new window

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
lkirkeAuthor Commented:
Fantastic. Thank you.
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.