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

Adam Elsheimer
Adam Elsheimer used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Excel & VBA Expert
Most Valuable Expert 2018
Awarded 2015
Commented:
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

Author

Commented:
Neeraj, thank you  for your quick and professional response and solution.

Regards,

Adam
Subodh Tiwari (Neeraj)Excel & VBA Expert
Most Valuable Expert 2018
Awarded 2015

Commented:
You're welcome Adam! Glad I could help.
And thanks for the feedback.
Rob HensonFinance Analyst

Commented:
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

Author

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

Regards,

Adam

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial