ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Step -1 method (https://www.excelbanter.com/excel-programming/427189-step-1-method.html)

K[_2_]

Step -1 method
 
Hi all, Just for knowledge that what kind of work "Step - 1" method
do and when it is used. Pleae can any friend can explain briefly as i
wasn't able to find much information about this method.

Jacob Skaria

Step -1 method
 
Step is optional numeric expression which denotes the amount by which counter
is incremented each time through the loop.

For intTemp = 10 to 1 Step-1
Next

will have intTemp values in the order 10,9,8,7,6,...

and Step -2 will have 10,8,6,4,2



If this post helps click Yes
---------------
Jacob Skaria


"K" wrote:

Hi all, Just for knowledge that what kind of work "Step - 1" method
do and when it is used. Pleae can any friend can explain briefly as i
wasn't able to find much information about this method.


Dave Peterson

Step -1 method
 
It's very useful when you want to process a range of rows from the bottom to the
top or a range of columns from the right to the left.

Dim iRow as long
with activesheet
for irow = 20 to 10 step -1
if .cells(irow,"A").value = "" then
.rows(irow).delete
end if
next irow
end with

or

Dim iCol as long
dim FirstCol as long
Dim LastCol as long
with activesheet
firstcol = 1
lastcol = .cells(1,.columns.count).end(xltoleft).column

for icol = lastcol to firstcol step -1
if .cells(1,icol).value = "" then
.columns(icol).delete
end if
next icol
end with

Or just when you want to loop through any old array in reverse order.

dim ictr as long
dim myArr as variant
myarr = array("something", "else","would", "go here")
for ictr = ubound(myArr) to lbound(myarr) step -1
msgbox myarr(ictr)
next ictr

Or loop through a string
dim iCtr as long
dim myStr as string

mystr = "Just for knowledge"
for ictr = len(mystr) to 1 step -1
msgbox mid(mystr, ictr, 1)
next ictr



K wrote:

Hi all, Just for knowledge that what kind of work "Step - 1" method
do and when it is used. Pleae can any friend can explain briefly as i
wasn't able to find much information about this method.


--

Dave Peterson

Jacob Skaria

Step -1 method
 
The below link would help

http://msdn.microsoft.com/en-us/library/5z06z1kb.aspx

If this post helps click Yes
---------------
Jacob Skaria


"K" wrote:

Hi all, Just for knowledge that what kind of work "Step - 1" method
do and when it is used. Pleae can any friend can explain briefly as i
wasn't able to find much information about this method.


K[_2_]

Step -1 method
 
On Apr 20, 1:11*pm, Jacob Skaria
wrote:
The below link would help

http://msdn.microsoft.com/en-us/library/5z06z1kb.aspx

If this post helps click Yes
---------------
Jacob Skaria



"K" wrote:
Hi all, *Just for knowledge that what kind of work "Step - 1" method
do and when it is used. Pleae can any friend can explain briefly as i
wasn't able to find much information about this method.- Hide quoted text -


- Show quoted text -


thanks guys its very helpful


All times are GMT +1. The time now is 04:16 AM.

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