Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Find Value < 0

Hello everybody!

Is there a possibiliy to find the last value of a list
that is not zero? Excel should search from the bottom of a
column and find the last entry < 0 ...

Thanks for your help,

Maria
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 111
Default Find Value < 0

This should do it....(assuming col a in sheet 1)

Sub FindNonZero()
Dim rngTarget As Range
Set rngTarget = Sheet1.Cells(65536, 1).End(xlUp)

While rngTarget.Value = 0
Set rngTarget = rngTarget.Offset(-1, 0)
Wend

MsgBox "the last non zero cell is " & rngTarget.Address
Set rngTarget = Nothing
End Sub

Hth,
OJ

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Find Value < 0

Thanks you! Worked fine ...
Maria


-----Original Message-----
This should do it....(assuming col a in sheet 1)

Sub FindNonZero()
Dim rngTarget As Range
Set rngTarget = Sheet1.Cells(65536, 1).End(xlUp)

While rngTarget.Value = 0
Set rngTarget = rngTarget.Offset(-1, 0)
Wend

MsgBox "the last non zero cell is " & rngTarget.Address
Set rngTarget = Nothing
End Sub

Hth,
OJ

.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Find Value < 0

Bit heavy setting a range every time isn't it. Also, maybe wise tol check
for none

Sub FindNonZero()
Dim rngTarget As Range
Dim i As Long
Set rngTarget = Sheet1.Cells(Rows.Count, 1).End(xlUp)

With rngTarget
If .Row = 1 And .Value = 0 Then
MsgBox "There are no non-zero values in this column"
Exit Sub
Else
While .Offset(-i, 0).Value = 0
i = i + 1
Wend
MsgBox "the last non zero cell is " & rngTarget.Offset(-i,
0).Address
End If
End With
Set rngTarget = Nothing
End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"OJ" wrote in message
ups.com...
This should do it....(assuming col a in sheet 1)

Sub FindNonZero()
Dim rngTarget As Range
Set rngTarget = Sheet1.Cells(65536, 1).End(xlUp)

While rngTarget.Value = 0
Set rngTarget = rngTarget.Offset(-1, 0)
Wend

MsgBox "the last non zero cell is " & rngTarget.Address
Set rngTarget = Nothing
End Sub

Hth,
OJ



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 111
Default Find Value < 0

fair point....



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 111
Default Find Value < 0

....taht said, just tried it on 65535 rows of 0's with the first non
zero in row 7 and it ran v quick. Does it take up that much
time/resource setting a range object? I dunno much about that side of
things...

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Find Value < 0

OJ,

I did a quick rough and ready timed test, and it is about 8 times slower to
set a range object that to just increment a long variable (this was less
than I expected!).

It is true that in the actual data set it would still be quick, but these
things all add up, and in a complex app, you want to be as efficient as
possible.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"OJ" wrote in message
oups.com...
...taht said, just tried it on 65535 rows of 0's with the first non
zero in row 7 and it ran v quick. Does it take up that much
time/resource setting a range object? I dunno much about that side of
things...



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 111
Default Find Value < 0

food for thought indeed!! Cheers Bob. I have no formal
programming/testing education so I would be very curious to see how you
timed this...if you get a moment would you mind emailing me some sample
code so i can see your approach? Unlike almost everybody who uses these
list, my email address really is, well, my email address!!! (Much to
the delight of spammers and phishers...do people really fall for
those???)

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find First Non blank cell than find column header and return that value Silver Rose Excel Worksheet Functions 10 April 30th 07 05:56 PM
Despite data existing in Excel 2002 spreadsheet Find doesn't find AnnieB Excel Discussion (Misc queries) 1 June 16th 06 02:15 AM
find and delete duplicate entries in two columns or find and prin. campare 2 columns of numbers-find unique Excel Programming 1 November 24th 04 04:09 PM
find and delete text, find a 10-digit number and put it in a textbox Paul Excel Programming 3 November 16th 04 04:21 PM
backwards find function to find character in a string of text Ashleigh K. Excel Programming 1 January 14th 04 04:36 PM


All times are GMT +1. The time now is 07:27 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"