'Update Blank Cells based on multiple criteria

I am trying to check preceding and succeeding cell values in a column and if the cell values match either preceding or succeeding then the corresponding blank cell will automatically get updated based on preceding or succeeding values. My current code only updates based on preceding value and also the blank cell evaluation criteria is not included. Can anyone solve this

Sub Update_Blank()

Dim sh As Worksheet
Dim y As Long

 Set sh = Sheets("Combine")

 For y = 4 To 22 'selected range'

 If sh.Cells(y, "X") = sh.Cells(y - 1, "X") and sh.Cells(y, "V").Value Then 'compares values 
  in Column X'
sh.Cells(y, "V").Value = sh.Cells(y - 1, "V").Value 'copies values from above if values in 
column X matches'

  End If
 Next y

 End Sub


Solution 1:[1]

If you want to fill the blank in the "V" column based on the values of the "X" column :

Sub Update_Blank()

    Dim sh As Worksheet
    Dim y As Long

    Set sh = Sheets("Combine")

    For y = 4 To 22 'selected range'
        If sh.Cells(y, "V") = "" Then 'if blank
            
            If (sh.Cells(y, "X") = sh.Cells(y - 1, "X") And sh.Cells(y, "X").Value = sh.Cells(y + 1, "X")) Then 'compares values in Column X'
                sh.Cells(y, "V").Value = sh.Cells(y - 1, "V").Value 'copies values from above if values in column X matches'
            End If
        End If
    Next y

 End Sub

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 AlexHhz