السلام عليكم أخي الكريم سيد
جرب الكود التالي عله يفي بالغرض إن شاء الله
Sub FillRandom()
Dim lngSum As Long
Dim i As Long
Dim arrValues(1 To 13) As Double
For i = 9 To Cells(Rows.Count, "B").End(xlUp).Row
If Cells(i, "P").Value <> "" Then
lngSum = Range("P" & i).Value
Do
arrValues(1) = Application.RandBetween(1, 10)
arrValues(2) = 10
arrValues(3) = Application.RandBetween(1, 20)
arrValues(4) = Application.Sum(arrValues(1), arrValues(2), arrValues(3))
arrValues(5) = Application.RandBetween(1, 10)
arrValues(6) = 10
arrValues(7) = Application.RandBetween(1, 20)
arrValues(8) = Application.Sum(arrValues(5), arrValues(6), arrValues(7))
arrValues(9) = Application.RandBetween(1, 10)
arrValues(10) = 10
arrValues(11) = Application.RandBetween(1, 20)
arrValues(12) = Application.Sum(arrValues(9), arrValues(10), arrValues(11))
Loop Until Application.Average(arrValues(4), arrValues(8), arrValues(12)) = lngSum
arrValues(13) = Application.Sum(arrValues(4), arrValues(8), arrValues(12))
Range("C" & i).Resize(1, 13).Value = arrValues
Range("R" & i).Value = Application.Sum(Range("P" & i).Value, Range("Q" & i).Value)
End If
Next i
End Sub