non-linear step count loop syntax?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



I have an existing workbook that requires modification. The workbook has
arrays that were built for earlier needs, and all of that data needs to be
retained (e.g. I can't change the arrays or their contents). However, I have
some code that used to loop through all elements of some arrays, and now I
need to be more selective.

Simplified example- my old code was

For x=3 to 10
'do stuff
Next

and now I need it to be
For X=3,5,7-10
'do stuff
Next

I've worked with linear loops and >1 step values, but I'm not sure how to
approach this type of non-linear loop- and I can't recall seeing any
examples anywhere that deal with this type of situation. What is the proper
syntax to use for the non-linear loop count? Or do I need to build a
separate array of my values (3,5,7,8,9,10 in this example) and reference it
as

MyArray= Array(3,5,7,8,9,10)
For Y = 1 to 6
X=MyArray(Y)
'do stuff
Next

Thanks,
Keith


.



Relevant Pages

  • RE: populate column of filtered worksheet A with data found in workshe
    ... arrays two visibile columns. ... Dim serverpos As Variant ... Next with workbook B active, filtered, and sorted, I would like to search ...
    (microsoft.public.excel.programming)
  • populate column of filtered worksheet A with data found in workshe
    ... Workbook A has been filtered. ... arrays two visibile columns. ... Dim serverpos As Variant ...
    (microsoft.public.excel.programming)
  • Re: Can you help me figure out why my macro is running slowly?
    ... then the first question I would have would be where is ... time variance in the amount of time it takes to run. ... Size the arrays to 1000 elements using ReDim. ... Write computed values to the workbook opened in step 3. ...
    (microsoft.public.excel.programming)
  • Re: non-linear step count loop syntax?
    ... arrays that were built for earlier needs, and all of that data needs to be retained (e.g. ... I can't change the arrays or their contents). ... However, I have some code that used to loop through all elements of some arrays, and now I need to be more selective. ... What is the proper syntax to use for the non-linear loop count? ...
    (microsoft.public.excel.programming)
  • Re: how can I see if an array contain a certain variable?
    ... it is not the same workbook why not compare the workbook objects? ... > At least do I belive I should use arrays to solve it, ... I want to compare if the Target ... > into one of my known sheets or if it is an unknown sheet. ...
    (microsoft.public.excel.programming)