Thread: Step -1 method
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default 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