Deleted code in red
Added code in blue
Sub sFind()
On Error Resume Next
Dim lr(5)
Dim f(4)
f(1) = 1stFormula
f(2) = 2ndFormula
f(3) = 3rdFormula
f(4) = 4thFormula
Dim n As Integer
Dim lineRow1 As Integer
Dim lineRow2 As Integer
Dim lineRow3 As Integer
Dim lineRow4 As Integer
Dim lineRow5 As Integer
Dim sLineNo As String
n = 1
Range("D5").Select
Do
For n = 1 to 5
lr(n) = Cells.Find(What:="Line-" & n, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Row
If n > 1 then Range(Cells(lr(n-1),1),Cells(lr(n)-1,1)).formula = f(n-1)
Next
sLineNo = ActiveCell.Value
Select Case sLineNo
Case "Line-1"
lineRow1 = ActiveCell.Row
Case "Line-2"
lineRow2 = ActiveCell.Row
Case "Line-3"
lineRow3 = ActiveCell.Row
Case "Line-4"
lineRow4 = ActiveCell.Row
Case "Line-5"
lineRow5 = ActiveCell.Row
End Select
n = n + 1
Loop Until n >= 5
nN = 1
Range("D5").Select
Do Cells.Find(What:="Line-" & nN, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
sLineNo = ActiveCell.Value
Select Case sLineNo
Case "Line-1"
Range("A" & lineRow1 :A" & lineRow2 - 1).Formula = 1stFormula
Case "Line-2"
Range("A" & lineRow2 :A" & lineRow3 - 1).Formula = 2ndFormula
Case "Line-3"
Range("A" & lineRow3 :A" & lineRow4 - 1).Formula = 3rdFormula
Case "Line-4"
Range("A" & lineRow4 :A" & lineRow5 - 1).Formula = 4thFormula
End Select
nN = nN + 1
Loop Until nN >= 5
End Sub
Bookmarks