Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 355
Default How to Question

I have an array with let's say 10 numeric values. How can I finf the lowest
non zero value and its position in the array.

Thank you
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 272
Default How to Question

Sandy, I can do this with a loop but I'm not sure if this is the best way.
Dim dMin As Double
Dim lPostion As Long
Dim cnt As Long
dMin = SandyArr(LBound(SandyArr))
lPosition = LBound(SandyArr)
For cnt = LBound(SandyArr) to UBound(SandyArr)
If SandyArr(cnt) < dMin Then
dMin = SandyArr(cnt)
lPosition = cnt
End If
Next
MsgBox "The lowest value in Sandy's array is: " & dMin & _
vbCrLF & "And is in position: " & lPosition
--
Charles Chickering

"A good example is twice the value of good advice."


"Sandy" wrote:

I have an array with let's say 10 numeric values. How can I finf the lowest
non zero value and its position in the array.

Thank you

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 355
Default How to Question

Thank you. How can I find the lowest non zero (< 0) value and its position
in the array.


"Charles Chickering" wrote:

Sandy, I can do this with a loop but I'm not sure if this is the best way.
Dim dMin As Double
Dim lPostion As Long
Dim cnt As Long
dMin = SandyArr(LBound(SandyArr))
lPosition = LBound(SandyArr)
For cnt = LBound(SandyArr) to UBound(SandyArr)
If SandyArr(cnt) < dMin Then
dMin = SandyArr(cnt)
lPosition = cnt
End If
Next
MsgBox "The lowest value in Sandy's array is: " & dMin & _
vbCrLF & "And is in position: " & lPosition
--
Charles Chickering

"A good example is twice the value of good advice."


"Sandy" wrote:

I have an array with let's say 10 numeric values. How can I finf the lowest
non zero value and its position in the array.

Thank you

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default How to Question

how about this? it sorts the array and the lowest number will be arr(0)

modified from someone's code here


Sub sort_array()
Dim arr As Variant
Dim i As Long, j As Long, temp As Long
'sort the array
arr = Array(2, 3, 4, 1, 6, 8,7)
For i = LBound(arr) To UBound(arr) - 1
For j = i + 1 To UBound(arr)
If arr(i) arr(j) Then
temp = arr(j)
arr(j) = arr(i)
arr(i) = temp
End If
Next j
Next i
MsgBox arr(0)
End Sub

--


Gary


"Sandy" wrote in message
...
I have an array with let's say 10 numeric values. How can I finf the lowest
non zero value and its position in the array.

Thank you



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default How to Question

sandy:

if you use the method i posted, it would be contained in arr(1), assuming there
is a zero in the array. are there negative numbers?

try it with your numbers and let me know what happens

--


Gary


"Sandy" wrote in message
...
Thank you. How can I find the lowest non zero (< 0) value and its position
in the array.


"Charles Chickering" wrote:

Sandy, I can do this with a loop but I'm not sure if this is the best way.
Dim dMin As Double
Dim lPostion As Long
Dim cnt As Long
dMin = SandyArr(LBound(SandyArr))
lPosition = LBound(SandyArr)
For cnt = LBound(SandyArr) to UBound(SandyArr)
If SandyArr(cnt) < dMin Then
dMin = SandyArr(cnt)
lPosition = cnt
End If
Next
MsgBox "The lowest value in Sandy's array is: " & dMin & _
vbCrLF & "And is in position: " & lPosition
--
Charles Chickering

"A good example is twice the value of good advice."


"Sandy" wrote:

I have an array with let's say 10 numeric values. How can I finf the lowest
non zero value and its position in the array.

Thank you





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 355
Default How to Question

Thank you very much for your advice and time. I took your original suggestion
and embedded it in my routine and added a couple if statements to "filter
out" unwanted results and it works great. Thanks again.

"Gary Keramidas" wrote:

how about this? it sorts the array and the lowest number will be arr(0)

modified from someone's code here


Sub sort_array()
Dim arr As Variant
Dim i As Long, j As Long, temp As Long
'sort the array
arr = Array(2, 3, 4, 1, 6, 8,7)
For i = LBound(arr) To UBound(arr) - 1
For j = i + 1 To UBound(arr)
If arr(i) arr(j) Then
temp = arr(j)
arr(j) = arr(i)
arr(i) = temp
End If
Next j
Next i
MsgBox arr(0)
End Sub

--


Gary


"Sandy" wrote in message
...
I have an array with let's say 10 numeric values. How can I finf the lowest
non zero value and its position in the array.

Thank you




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
Newbie Question - Subtraction Formula Question [email protected] Excel Discussion (Misc queries) 3 May 5th 06 05:50 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good davegb Excel Programming 1 May 6th 05 06:35 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 0 April 27th 05 07:46 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 23 April 23rd 05 09:26 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 0 April 22nd 05 03:30 PM


All times are GMT +1. The time now is 01:32 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"