ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   For Each...Next statement (https://www.excelbanter.com/excel-programming/301619-each-next-statement.html)

Hardy[_5_]

For Each...Next statement
 
Hi,

Not that familiar with loops etc.

I think what I need is for..next statement loop, as this is for each
element in group.

My group would be list of varialbes (integers) that are non-sequential,
that are gained via match function in VBA (they are column numbers of
data).

So, looping through 1,4,7,9,15 etc., rather than 1,2,3,4 etc.

I have searched and searched but cannot get my head round how to create
group or array to achieve this.

The code that I want to use in my loop is below (not that relevant to
question);

Set riBoxxFilteredCol = Intersect(ActiveSheet.Columns(iIBOXXColNo),
rng) ' Loops through series of integer variables
riBoxxFilteredCol.Copy
Worksheet(NowSheetName).Activate
Range("B1").Activate
ActiveCell.Offset(0, iNowColNo).Activate ' This is varialbe in loop (1
to 9)

It's iBOXXColNo that will loop through non-sequential list mentioned
above.

Thanks in advance.


---
Message posted from http://www.ExcelForum.com/


Tom Ogilvy

For Each...Next statement
 
varr = Array( 1,4,7,9,15)

for i = lbound(varr) to ubound(varr)
iIBOXXColNo = varr(i)
. . .

Next

--
Regards,
Tom Ogilvy


"Hardy " wrote in message
...
Hi,

Not that familiar with loops etc.

I think what I need is for..next statement loop, as this is for each
element in group.

My group would be list of varialbes (integers) that are non-sequential,
that are gained via match function in VBA (they are column numbers of
data).

So, looping through 1,4,7,9,15 etc., rather than 1,2,3,4 etc.

I have searched and searched but cannot get my head round how to create
group or array to achieve this.

The code that I want to use in my loop is below (not that relevant to
question);

Set riBoxxFilteredCol = Intersect(ActiveSheet.Columns(iIBOXXColNo),
rng) ' Loops through series of integer variables
riBoxxFilteredCol.Copy
Worksheet(NowSheetName).Activate
Range("B1").Activate
ActiveCell.Offset(0, iNowColNo).Activate ' This is varialbe in loop (1
to 9)

It's iBOXXColNo that will loop through non-sequential list mentioned
above.

Thanks in advance.


---
Message posted from http://www.ExcelForum.com/




Hardy[_6_]

For Each...Next statement
 
Thanks v. much for you help today, Tom

--
Message posted from http://www.ExcelForum.com



All times are GMT +1. The time now is 10:16 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com