ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   reset the range of FOR loop (https://www.excelbanter.com/excel-discussion-misc-queries/226960-reset-range-loop.html)

Farooq Sheri

reset the range of FOR loop
 
I have the following bit of code in my macro.

For colCnt = 2 To lstCol

(lines of code here)

Next colCnt

Within the For loop certain conditions require changing the value of lstCol
(say it was 5 initially and it becomes 6). Is there a way to ensure that loop
executes till colCnt = 6 (inclusive). I tried setting lstCol = 6 but the loop
excutes only uptil 5.

Thanks for your help.

Gary''s Student

reset the range of FOR loop
 
"for"get FOR. Use While:

Sub loopy()
topp = 5
i = 1
While i < topp
MsgBox (i)
topp = 8
i = i + 1
Wend
End Sub
--
Gary''s Student - gsnu200843


"Farooq Sheri" wrote:

I have the following bit of code in my macro.

For colCnt = 2 To lstCol

(lines of code here)

Next colCnt

Within the For loop certain conditions require changing the value of lstCol
(say it was 5 initially and it becomes 6). Is there a way to ensure that loop
executes till colCnt = 6 (inclusive). I tried setting lstCol = 6 but the loop
excutes only uptil 5.

Thanks for your help.



All times are GMT +1. The time now is 02:29 PM.

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