-2

good people, I have a table full of unique id's (as mentioned below) but there are missing values for few id's.

I want a formula/code to fill in the blanks based on the values above and below of any cell.

For example: here there are two empty rows between two unique id~(620006845180).

can anyone help me with filling up these spaces with the same value as above and below. :( I am stuck.

    620006845180
    xxxxxxxxxxxx
    xxxxxxxxxxxx
    620006845180
    620006845180
Community
  • 1
  • 1

2 Answers2

1

ok, sure. this assumes the id's are in column A

Sub FillBlankCells() 

Dim lastRow As Long: lastRow = Cells(Rows.Count, 1).End(xlUp).Row
Dim IDRange As Range: Set IDRange = Range("A1:A" & lastRow)
Dim rng As Range

For Each rng In IDRange
  If rng.Value = "" Then
    If rng.End(xlUp).Value = rng.End(xlDown).Value Then _
    rng.Value = rng.End(xlUp).Value
  End If
Next rng

End Sub
luckyguy73
  • 1,850
  • 2
  • 11
  • 21
1

You cannot do this in a same column because of circular reference. But you can use another column to do it.

I assume that you have these numbers in column A and from row 2 and you insert an empty column in B and you enter the following formula in B2. Then copy the rest of the rows of the column B from the cell B2. Then Hide your column A, you will get what you wanted in column B.

=IF(A2<>"",A2,IFERROR(IF(MATCH(B1,A3:A100,0)>0,B1,""),""))

If you feel there could more than 100 empty rows. Then you may need to replace the 100 found in the formula to what is the maximum number of rows that you expect to be empty.

Karpak
  • 1,927
  • 1
  • 15
  • 16