View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Handling an array

Another one:

Dim res As Variant 'could be an error
Dim myArr As Variant
Dim myStart As Long
Dim iCtr As Long

myArr = Array(2, 4, 6, 8, 10)
myStart = 6

res = Application.Match(myStart, myArr, 0)

If IsError(res) Then
'not a valid starting position!
'what should happen?
MsgBox "No match"
Else
For iCtr = LBound(myArr) + res - 1 To UBound(myArr)
MsgBox myArr(iCtr)
Next iCtr
End If


Otto Moehrbach wrote:

Excel XP & Win XP
I need some help with an array problem.
I have an array of column numbers, say, 2,4,6,8,10. This array is fixed. I
want to run a FOR loop through this array. The variable is the point at
which I want to start. IOW, my target (or starting) column may be, say, 6.
I then want to run the FOR loop through columns 6,8,10 only.
My question is then: Given the starting column, how would I code a FOR loop
through this array? Thanks for your time. Otto


--

Dave Peterson