Please place this in your worksheet's module.
It checks, whether cell B2 is changed and contains something, and then places the formula in whole range, starting at I2:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim RelevantArea As Range
Dim lastRow As Long
Set RelevantArea = Intersect(Target, Me.Range("B2"))
If Not RelevantArea Is Nothing Then
If Len(Target.Value2) > 0 Then
' find the last used row, e. g. in column 9:
lastRow = Me.Cells(Me.Rows.Count, 9).End(xlUp).Row
Application.EnableEvents = False
Me.Range("I2:AD" & lastRow).Formula = "=IF(I$1=$D2,$G2,"""")"
Application.EnableEvents = True
End If
End If
End Sub
The formula is inserted into the range like you would get it, if you copy the formula of the first cell (here: I2) to the rest of the range. I changed the formula a little, assuming you wanted it like that.
By following you get it for the changed row only, i. e. if you paste into e. g. B5:B9, it works for rows 5 to 9.
You can use the A1- or R1C1-notation to adapt the formula to your needs.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim MonitoredArea As Range
Dim CurrentRow As Long
Dim CurrentCell As Range
Set MonitoredArea = Intersect(Target, Me.Range("B:B"))
If Not MonitoredArea Is Nothing Then
For Each CurrentCell In MonitoredArea.Cells
If Len(CurrentCell.Value2) > 0 Then
CurrentRow = CurrentCell.Row
Application.EnableEvents = False
With Me.Range(Me.Cells(CurrentRow, "I"), Me.Cells(CurrentRow, "AD"))
.Formula = "=IF(I$1=$D" & CurrentRow & ",$G" & CurrentRow & ","""")"
'.FormulaR1C1 = "=IF(R1C=RC4,RC7,"""")"
Dim i As Integer
For i = xlEdgeLeft To xlInsideHorizontal ' all borders
With .Borders(i)
.LineStyle = xlContinuous
.Weight = xlThin
.Color = RGB(0, 0, 0)
.TintAndShade = 0
End With
Next i
End With
Application.EnableEvents = True
End If
Next CurrentCell
End If
End Sub