RAYLWARD102
Well-known Member
- Joined
- May 27, 2010
- Messages
- 529
The below example will not work because of the If ASC = statement; Does not allow you to do this when starting a for loop. Any ideas as to how I could do this without duplicating code twice? In my production code, have many procedures inside the loop and would rather edit them once; if I have 2 procedures based on backwards or forwards through loop, I'm editing inside procedures twice. Wish it wasn't necessary to type step -1
Any ways around this ?
Any ways around this ?
Code:
Dim ASC As Boolean
Dim PointA As Long
Dim PointB As Long
List = Split("1,2,3,4,5", ",")
ASC = False
Select Case ASC
Case True
PointA = 0
PointB = UBound(List)
Case False
PointA = UBound(List)
PointB = 0
End Select
If ASC = True Then
For iCnt = PointA To PointB
Else:
For iCnt = PointA To PointB Step -1
End If
Debug.Print List(iCnt)
Next iCnt