View Single Post
  #27   Report Post  
Posted to microsoft.public.excel.programming
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default Last used cell in column

It happens that Rick Rothstein formulated :
If Len(Cells(n, 1)) 0 And Not Cells(n, 1) = " " Then _
is a good way and place to deal with that


Why not just combine the two tests like this...

=If Len(Trim(Cells(n, 1))) Then

Trim will collapse the space to an empty string if it is there and then the
Len function will return 0 for it. Note that I did not bother to explicitly
test if the Len function's return value is greater than zero because that
extra test is not necessary. The Len function can only return zero or
positive whole numbers. A logical expression (normally one where two
expressions are tested for being equal, not equal, greater than, etc.)
evaluates to True or False; however, when a logical expression is required
(such as in an If..Then test), VB considers 0 as False and any non-zero value
as True. If the Len function returns 0, then there are no characters in the
text, so a Len(...)0 would be False (the same number returned by the Len
function itself. On the other hand, if the Len function returns a non-zero
value, then that value must automatically be greater than 0 (Len cannot
return negative values), so the Len(..)0 test would be True, but the
non-zero positive value of the Len function's return value would also be
considered True by the If..Then test. Since these are the only possibilities,
you do not need to specifically test the return value for being greater than
0 inside the If..Then statement.

Rick Rothstein (MVP - Excel)


Excellent! Makes perfect sense to me. (Now why didn't I think of
that?<g)

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc