Help: How do I fill a column with values if it is blank?

L

limshady411

Hello,

How do I fill a column of cells with values if it is empty? I want to
fill empty cells with a 0 (zero). The tricky part is, the cells should
only be filled if they are in a row. For instance, A25 has data in it,
but B25 doesn't, but some cells in column b has value, so b25 needs to
have a zero in it since it is in row 25.

I'm not sure how to approach this.

Thanks!
 
R

Rowan Drummond

Wild guess:

Sub BVals()
Dim eRow As Long
Dim ColB As Range
Dim cell As Range
eRow = Cells(Rows.Count, 1).End(xlUp).Row
Set ColB = Range(Cells(2, 2), Cells(eRow, 2))
For Each cell In ColB
If cell.Offset(0, -1).Value <> Empty _
And cell.Value = Empty Then cell.Value = 0
Next cell
End Sub

Hopet this helps
Rowan
 
L

limshady411

Thanks...this didn't work, but good try. I guess maybe, all I need i
to make sure that in the last row of a spreadsheet, if it is an empt
cell, make it a 0. This might be easier. Any ideas? Thanks everyone
 
R

Rowan Drummond

It is still not all that clear what you are after so if this doesn't
work try to give a more detailed explanation of what it is you want to
achieve. This assumes you have data in column A. It checks the last cell
in Column B and if this is empty inserts a 0:

Sub lrow()
Dim eRow As Long
eRow = Cells(Rows.Count, 1).End(xlUp).Row
With Cells(eRow, 2)
If .Value = Empty Then .Value = 0
End With
End Sub

Regards
Rowan
 
L

limshady411

Thanks for your help. I can make it simpler. I want to fill all cells in
a row with a value of zero. How would I go about this? Thanks again!
 
R

Rowan Drummond

Trying to make it simplier is what is complicated the issue. This is why
I requested a detailed explanation in my last post. How do you determe
the last row eg is it the last row with a value in column A?. Also, how
many columns do you want to fill with 0? Will the columns you do not
want to fill with 0 have formulae or constant values? Etc Etc.

Regards
Rowan
 

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