Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default Application.Min - how to ignore zero value?

How do I determine the lowest non-zero value in a range?

This works if the lowest value is NOT zero:

dblMin = xlapp.Min(xlapp.Workbooks(strXlsFile).
Worksheets(sn(i)).Range(xlapp.Workbooks(strXlsFile ).
Worksheets(sn(i)).Cells(2, 4), xlapp.Workbooks(strXlsFile).
Worksheets(sn(i)).Cells(lr, lc)))
[lr = last row, lc = last column]

Is there some way to ignore zero values?



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Application.Min - how to ignore zero value?

Here is an example

Debug.Print Evaluate("MIN(IF(A1:A10<0,A1:A10))")

--

HTH

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


"deko" wrote in message
om...
How do I determine the lowest non-zero value in a range?

This works if the lowest value is NOT zero:

dblMin = xlapp.Min(xlapp.Workbooks(strXlsFile).
Worksheets(sn(i)).Range(xlapp.Workbooks(strXlsFile ).
Worksheets(sn(i)).Cells(2, 4), xlapp.Workbooks(strXlsFile).
Worksheets(sn(i)).Cells(lr, lc)))
[lr = last row, lc = last column]

Is there some way to ignore zero values?





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default Application.Min - how to ignore zero value?

Debug.Print Evaluate("MIN(IF(A1:A10<0,A1:A10))")

Correct me if I'm wrong, but I believe this is saying: "If there is no zero
value in range A1:A10, then return the minimum value in the range". But
what if there *is* a zero value? How then would I get the minimum non-zero
value in the range?

In Access VBA, I think it would look like this:

MinVal = DMin("fldName", "tblName", "fldName 0")

But all I have is a range in an Excel worksheet.

Perhaps I could assign the min value in the range to a variable, then test
the variable and get the average:

If MinVal = 0 Then
dblMin = xlapp.Average(myRange)
End if

Then increment down until 0

Do While MinVal 0
MinVal = MinVal - x
Loop

But this could be inefficient - especially if I don't know how much to
increment down with each loop. Perhaps I could guess somehow by getting the
max and/or the standard deviation? The reason I need the min value is to
set the Y-axis on a chart - so it does not have to be absolutely precise,
but it does need to be pretty close.

Other ideas?

Thanks for the help.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Application.Min - how to ignore zero value?

No it is saying take the minimum of all values in the rfange that are not
zero.

Why don't you try it?

--

HTH

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


"deko" wrote in message
om...
Debug.Print Evaluate("MIN(IF(A1:A10<0,A1:A10))")


Correct me if I'm wrong, but I believe this is saying: "If there is no

zero
value in range A1:A10, then return the minimum value in the range". But
what if there *is* a zero value? How then would I get the minimum

non-zero
value in the range?

In Access VBA, I think it would look like this:

MinVal = DMin("fldName", "tblName", "fldName 0")

But all I have is a range in an Excel worksheet.

Perhaps I could assign the min value in the range to a variable, then test
the variable and get the average:

If MinVal = 0 Then
dblMin = xlapp.Average(myRange)
End if

Then increment down until 0

Do While MinVal 0
MinVal = MinVal - x
Loop

But this could be inefficient - especially if I don't know how much to
increment down with each loop. Perhaps I could guess somehow by getting

the
max and/or the standard deviation? The reason I need the min value is to
set the Y-axis on a chart - so it does not have to be absolutely precise,
but it does need to be pretty close.

Other ideas?

Thanks for the help.




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default Application.Min - how to ignore zero value?

No it is saying take the minimum of all values in the rfange that are not
zero.


I see. I should know by now not to second guess you...

Debug.Print Evaluate("MIN(IF(xlapp. _
Workbooks(strXlsFile).Worksheets(sn(i)). _
Range(xlapp.Workbooks(strXlsFile). _
Worksheets(sn(i)).Cells(2, 4), xlapp. _
Workbooks(strXlsFile).Worksheets(sn(i)). _
Cells(lr, lc))) < 0, xlapp.Workbooks _
(strXlsFile).Worksheets(sn(i)).Range(xlapp.Workboo ks _
(strXlsFile).Worksheets(sn(i)).Cells(2, 4), xlapp. _
Workbooks(strXlsFile).Worksheets(sn(i)).Cells(lr, lc))))")

Result: Error 2015

Is this caused by the input string being too long?




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default Application.Min - how to ignore zero value?

Yes, Evaluate does have limitations, the length of the string being one
of them. However, in this case, it is something else.

Evaluate argument must be an XL formula. XL doesn't understand any
Workbooks mumbo-jumbo, which is VBA-speak. You need to convert your
range into a XL-type range reference, i.e.,
MIN(IF('[Book1]Sheet 1'!$A$1:$A$16<0,'[Book1]Sheet 1'!$A$1:$A$16))

Use something like the untested:

dim RngAddr as string
....
with xlapp.workbooks(strxlsfile).worksheets(sn(i))
rngaddr="'[" & .parent.name & "]" & .name & "'!"
RngAddr=rngaddr & .Range(.Cells(2, 4),.Cells(lr, lc))).address
end with
debug.print xlapp.evaluate( _
"MIN(IF(" & rngaddr & "<0," & rngaddr & "))")
....

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
No it is saying take the minimum of all values in the rfange that are not
zero.


I see. I should know by now not to second guess you...

Debug.Print Evaluate("MIN(IF(xlapp. _
Workbooks(strXlsFile).Worksheets(sn(i)). _
Range(xlapp.Workbooks(strXlsFile). _
Worksheets(sn(i)).Cells(2, 4), xlapp. _
Workbooks(strXlsFile).Worksheets(sn(i)). _
Cells(lr, lc))) < 0, xlapp.Workbooks _
(strXlsFile).Worksheets(sn(i)).Range(xlapp.Workboo ks _
(strXlsFile).Worksheets(sn(i)).Cells(2, 4), xlapp. _
Workbooks(strXlsFile).Worksheets(sn(i)).Cells(lr, lc))))")

Result: Error 2015

Is this caused by the input string being too long?



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
Ignore David Excel Discussion (Misc queries) 1 February 14th 10 06:16 PM
ignore #n/a GENO Excel Discussion (Misc queries) 2 November 25th 09 02:41 PM
Ignore #DIV/0! DLZ217 Excel Worksheet Functions 4 April 26th 05 03:20 AM
macro to close excel application other than application.quit mary Excel Programming 1 September 14th 04 03:43 PM
application.quit will not shut off application john Excel Programming 0 January 9th 04 11:29 PM


All times are GMT +1. The time now is 09:08 AM.

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

About Us

"It's about Microsoft Excel"