Formula in Excel or vba to transfer values from Column X to Y

I have to transfer the values in Col E to Col D without overwriting the values in Col D if values exists in cells.

The value = 0 or all empty cells in Col. D should be overwritten by the values from Col. E

Filter, Copy & Paste is a bit difficult if I have 50000 rows.

Screen
As always thank you for you assistance and effort.

Regards

Adam
Sample.xlsx
Adam ElsheimerAsked:
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.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You may try something like this....
Sub TransferValues()
Dim lr As Long, i As Long
Dim x
lr = Range("D:E").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
x = Range("D1:E" & lr).Value
For i = 1 To UBound(x, 1)
    If x(i, 1) = "" Or x(i, 1) = 0 Then
        x(i, 1) = x(i, 2)
    End If
Next i
Range("D1").Resize(UBound(x, 1), 2).Value = x
End Sub

Open in new window

1

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
Adam ElsheimerAuthor Commented:
Neeraj, thank you  for your quick and professional response and solution.

Regards,

Adam
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome Adam! Glad I could help.
And thanks for the feedback.
0
Rob HensonFinance AnalystCommented:
Formula option, in column F:

=IF(AND(D2<>"",D2<>0),D2,E2)

Copy/drag down as far as required and then Copy and paste Values into column D.

Alternative with the screen shot data, copy all of column E data and then do paste Special on column D, choose Values and at the bottom left of the Paste Special window choose Skip Blanks. This will ignore any blank cell from the copied range and will leave the value in column D.

Thanks
Rob H
1
Adam ElsheimerAuthor Commented:
Thank you Rob. I just noted this fomular for future project. Thanks all of you so much for helping.

Regards,

Adam
0
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.