ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Fill the cell in column D if column D is empty (https://www.excelbanter.com/excel-programming/395354-fill-cell-column-d-if-column-d-empty.html)

bartman1980

Fill the cell in column D if column D is empty
 
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?


joel

Fill the cell in column D if column D is empty
 
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


"bartman1980" wrote:

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?



bartman1980

Fill the cell in column D if column D is empty
 
On 13 aug, 13:04, Joel wrote:
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



"bartman1980" wrote:
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?- Tekst uit oorspronkelijk bericht niet weergeven -


- Tekst uit oorspronkelijk bericht weergeven -


Thank you very much, this works!



All times are GMT +1. The time now is 01:45 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com