Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
loops and If's
I'm still learning about loops and If statements.
I am matching two IF conditions and then return a value (per). I am trying to work out how to speed up the code. As Once it reaches "per = ShirePer" line I wan it to go to the next step in the macro. Currently it finds the correct value but then proceeds to check the next r until rnumrows occurs. How do you speed this up? Any directions would be appreciated. Thanks in advance David --------- Sub dummy() For y = 1 To 7 ZnumRows = Worksheets("Zones Raw Data").UsedRange.Rows.Count - 8 For zr = 1 To ZnumRows With Worksheets("Zones Raw Data") ZoneCatch = .Cells(8 + zr, (2 * y)) Zoneshire = .Cells(8 + zr, (2 * y) + 1) End With 'STEP 2 'Get Shires % col = Worksheets("Zone Definitions").Range("f2") rnumrows = Worksheets("Area %").UsedRange.Rows.Count - 8 For r = 1 To rnumrows With Worksheets("Area %") 'shireCatch =Catchment name PerCatchName = .Cells(8 + r, 1 + (col - 1) * 3) 'ShireName% = name of shire in the catchment ShireNamePer = .Cells(8 + r, ((col * 3) - 1)) 'Shire % = % in that shire in that catchment ShirePer = .Cells(8 + r, col * 3) End With 'Find matching percentage If ZoneCatch < 0 Then If ZoneCatch = PerCatchName Then If Zoneshire = ShireNamePer Then per = ShirePer End If End If End If Next r 'next stage of the calculations Next zr Next y |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
loops and If's
Sorry for the trouble I just found out how to do it.
I just needed a Exit For statement If ZoneCatch < 0 Then If ZoneCatch = PerCatchName Then If Zoneshire = ShireNamePer Then per = ShirePer Exit For End If End If End If |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Loops | Excel Discussion (Misc queries) | |||
For next loops | Excel Discussion (Misc queries) | |||
Do loops | Excel Discussion (Misc queries) | |||
Loops etc. | Excel Programming | |||
Loops | Excel Programming |