For every empty cell in a column, copy the value from the above ce

C

Charles Robe

Good afternoon!

I have a sheet which is keeping track of miscellaneous inventory items. In
Column A, there are several cells with values of even numbers and the cell
directly below that is empty.

What I am trying to achieve is populating the empty cells to have a value of
the cell above it (the even number value cell) plus 1.

In other words, if the value of cell A:2 is 1000, then cell A:3 will be
1001. If the value of cell A:4 is 1200, then cell A:5 will be 1201 and so
forth until the end of the column.

Thank you, in advance, for your help!
 
P

Per Jessen

Hello

Try this:

Sub FillIn()
Dim TargetCell As Range
Set TargetCell = Range("A2")

Do Until TargetCell.Value = ""
If TargetCell.Offset(1, 0).Value = "" Then
TargetCell.Offset(1, 0) = TargetCell.Value + 1
Set TargetCell = TargetCell.Offset(2, 0)
End If
Loop
End Sub

Regards,
Per
 
M

Mike

maybe something like this
Sub evenNumbers()
Dim rng, cell As Range
Set rng = Range(Cells(1, 1), Cells(Rows.Count, 1).End(xlUp))
For Each cell In rng
If cell.Value Mod 2 = 0 Then
If cell.Offset(1, 0).Value = "" Then
cell.Offset(1, 0).Value = cell.Value + 1
Else
End If
End If
Next cell
End Sub
 

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