Hello all, I am hoping for someone to examine my code below and advise on how to make it run more efficiently. Thanks in advance.
Sub sFind()
On Error Resume Next
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
Cells.Find(What:="Line-" & n, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
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