Copy and Paste IF Cell in column is empty

Sharid

Well-known Member
Joined
Apr 22, 2007
Messages
1,066
Office Version
  1. 2016
Platform
  1. Windows
Hi

I need a code that will copy and paste data from column D to column B if column B is empty, the code will ignore any empty cells in column D and move to the next cell with data to copy over.

From this[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]D[/TD]
[/TR]
[TR]
[TD]JANE[/TD]
[TD][/TD]
[TD]JANE[/TD]
[TD]DOE[/TD]
[/TR]
[TR]
[TD]JOHN[/TD]
[TD]DOE[/TD]
[TD]JOHN[/TD]
[TD]DOE[/TD]
[/TR]
[TR]
[TD]JANE[/TD]
[TD][/TD]
[TD]JANE[/TD]
[TD]SMITH[/TD]
[/TR]
[TR]
[TD]JOHN[/TD]
[TD]SMITH[/TD]
[TD]JOHN[/TD]
[TD]SMITH[/TD]
[/TR]
[TR]
[TD]JAMES[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]JILL[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]JACK[/TD]
[TD][/TD]
[TD]JACK[/TD]
[TD]JONES[/TD]
[/TR]
</tbody>[/TABLE]


To This

[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]D[/TD]
[/TR]
[TR]
[TD]JANE[/TD]
[TD]DOE[/TD]
[TD]JANE[/TD]
[TD]DOE[/TD]
[/TR]
[TR]
[TD]JOHN[/TD]
[TD]DOE[/TD]
[TD]JOHN[/TD]
[TD]DOE[/TD]
[/TR]
[TR]
[TD]JANE[/TD]
[TD]SMITH[/TD]
[TD]JANE[/TD]
[TD]SMITH[/TD]
[/TR]
[TR]
[TD]JOHN[/TD]
[TD]SMITH[/TD]
[TD]JOHN[/TD]
[TD]SMITH[/TD]
[/TR]
[TR]
[TD]JAMES[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]JILL[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]JACK[/TD]
[TD]JONES[/TD]
[TD]JACK[/TD]
[TD]JONES[/TD]
[/TR]
</tbody>[/TABLE]


Hope this makes sense
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Place this formula in B1 and copy down: =IF(D1<>"",D1,"")
If you prefer a macro, please let me know.
 
Upvote 0
How about
Code:
Sub Sharid()
   With Range("B2", Range("A" & Rows.count).End(xlUp).Offset(, 1))
      .SpecialCells(xlBlanks).FormulaR1C1 = "=if(rc[2]<>"""",rc[2],"""")"
      .Value = .Value
   End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top