View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Per Jessen[_2_] Per Jessen[_2_] is offline
external usenet poster
 
Posts: 703
Default multi Loop efficiency

Hi Chad

Thanks for your reply.

From what you write, I'm not sure how to determine which series should
be chosen and named.

Or maybe it's just me beeing tired..

Regards,
Per

On 20 Nov., 03:49, Chad wrote:
Per

Thanks very muchh for your help. *It certainly makes the full coding
shorter. *Your code works very well with one very small exception. *It
makes a named range for each of the scenarios 301 -310 and the same
for the 401-410 series. * I was not clear on this so I am very sorry.

I have some code that deletes all the named ranges that start with
"Test" prior to the loop begining.

I need to make one named range if the cell is either 301 or 401. * One
range if it is 302 or 402.

I then want to unlock this named range, then protect the sheet so we
can enter data against 301 but no where else on the sheet.

Here is the code in its entirety if this helps.
Chad

Sub Multiloop()

Dim FoundCell As Range
Dim mys As String
Dim myint As Integer
Dim i As Long
Dim LRw As Long
Dim nm As Name

Range("bid_phase").Value = Me.cmbBidPhase.Value
Range("bid_division").Value = Me.cmbBidDivision.Value

*'Remove all named ranges starting with Test, to clean sheet.

‘Remove all the names starting with Test
For Each nm In ThisWorkbook.Names
* * If UCase(Left(nm.Name, 4)) = "TEST" Then
* * * * nm.Delete
* * End If
*Next nm
*'First part not related to the Per LOOP
LRw = Range("W" & Rows.Count).End(xlUp).Row
If Range("bid_phase").Value = "Phase 900" Then
* For i = LRw To 1 Step -1
* * mys = Range("W" & i).Value
* * Set FoundCell = Range("B:B").Find(What:=mys, LookIn:=xlValues,
LookAt:=xlWhole, MatchCase:=0)
* * If FoundCell Is Nothing Then
* * * MsgBox "Not Found"
* * Else
* * * myint = FoundCell.Row
* * ' *Range("B" & myint & ":" & "C" & myint).Interior.Color = vbBlue
* * * Range("G" & myint & ":" & "U" & myint + 3).Name = "Test" & "_" &
myint
* * End If
* Next i

* 'Per LOOP part where multiple ranges are created. *Only one needed

*Else
* *For X = 1 To 10
* * TargetVal = 300 + X
* * TargetVal1 = 400 + X
* * *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 + X & ":" & "U" & myint + X).Name = "Test" &
"_" & myint + X

* * Next i
* Next
* End If

End Sub