Fill the cell in column D if column D is empty

B

bartman1980

I have a row of cells and I want to fill the cell in column D if
column D is empty.
I want to fill it with the information in the same cell but then
column B.
All cells are texts.
I've tried it, but I couldn't manage it because I want to fill the
cell which was empty first.

Does somebody have a suggestion for a VBA code?
 
J

Joel

Sub copycolb()

'use column B last row because lastt row in D may be empty
Lastrow = Cells(Rows.Count, "B").End(xlUp).Row
Set ColDRange = Range(Cells(1, "D"), Cells(Lastrow, "D"))


For Each cell In ColDRange

If IsEmpty(cell.Value) Then
cell.Value = cell. _
Offset(Rowoffset:=0, columnoffset:=-2).Value
End If
Next cell

End Sub
 
B

bartman1980

Sub copycolb()

'use column B last row because lastt row in D may be empty
Lastrow = Cells(Rows.Count, "B").End(xlUp).Row
Set ColDRange = Range(Cells(1, "D"), Cells(Lastrow, "D"))

For Each cell In ColDRange

If IsEmpty(cell.Value) Then
cell.Value = cell. _
Offset(Rowoffset:=0, columnoffset:=-2).Value
End If
Next cell

End Sub






- Tekst uit oorspronkelijk bericht weergeven -

Thank you very much, this works!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top