View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Chad[_12_] Chad[_12_] is offline
external usenet poster
 
Posts: 49
Default multi Loop efficiency

Hi

I was looking for a more efficient way to loop through a number of job
codes.

They go from 301 to 310 and 401 to 410. I am repeating the same code
10 times to get the job done and I was hoping someone could help with
a more efficient method. Problem is I have to increment the name
range by 1 each time.

I only included 2 loops for demonstration purposes.

Thanks in advance
chad

Sub Multiloop()

Dim i As Long
Dim LRw As Long


If Range("AAA").Value = "Phase 301" Or Range("AAA").Value = "Phase
401" Then
LRw = Range("Y" & Rows.Count).End(xlUp).Row
For i = LRw To 1 Step -1
mys = Range("Y" & i).Value
Set FoundCell = Range("C:C").Find(What:=mys, LookIn:=xlValues,
LookAt:=xlWhole, MatchCase:=0)
myint = FoundCell.Row 'Name range increment
Range("G" & myint + 1 & ":" & "U" & myint + 1).Name = "Test" &
"_" & myint + 1
End If
Next i

‘REPEAT CODE * 10 (NOT THAT EFFICIENT).

ElseIf Range("AAA").Value = "Phase 302" Or Range("AAA").Value =
"Phase 402" Then
LRw = Range("Y" & Rows.Count).End(xlUp).Row
For i = LRw To 1 Step -1
mys = Range("Y" & i).Value
Set FoundCell = Range("C:C").Find(What:=mys, LookIn:=xlValues,
LookAt:=xlWhole, MatchCase:=0)
myint = FoundCell.Row 'Name range increment
Range("G" & myint + 2 & ":" & "U" & myint + 2).Name = "Test" &
"_" & myint + 2
Next i

End If

End sub