Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8835113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:11:08+00:00 2026-06-14T09:11:08+00:00

I have an array (AlphaVector) with the following values: -0.2 -0.7 0 0.4 0.3

  • 0

I have an array (AlphaVector) with the following values:

-0.2
-0.7
0
0.4
0.3
0.1

I want to pick the positive values from the above array and place it in another array named Alpha so that I can pick the minimum positive value from Alpha. My goal is to get the value 0.1 from the above array.
Here’s the code I have so far. Alpha gets populated ok as the Msgbox indicates the correct values, but the return value I am getting is 0 instead of 0.1.

Function FindMin(AlphaVector)
Dim iCount As Long
Dim N As Integer, i As Integer
N = AlphaVector.Cells.Count
Dim Alpha() As Double
ReDim Alpha(N) As Double
For i = 1 To N
    If AlphaVector(i) > 0 Then
        Alpha(i) = AlphaVector(i)
    Else
        Alpha(i) = 100000000000#
    End If
    MsgBox ("Alpha(i)= " & Alpha(i))
    MsgBox ("AlphaVector(i)= " & AlphaVector(i))
Next i
FindMin = WorksheetFunction.Min(Alpha)
End Function

Can you please tell me how to fix it? Also, if there is a more efficient way to write it, perhaps without introducing Alpha, please let me know. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:11:09+00:00Added an answer on June 14, 2026 at 9:11 am

    You are using the wrong index for array Alpha. It is zero-based, and since you populate it by using i, starting from 1, you leave Alpha(0) to be the default, which is 0.

    WorksheetFunction.Min(Alpha) returns the smallest value, which you now know always will be 0. 🙂

    You need to redesign your function to handle this. Example will follow shortly.

    EDIT – code sample – updated to work as a UDF

    I finished this sample before I saw your comments, so in my code AlphaVector is an array. Anyway, it is always better to explicitly declare any variables and avoid the Variant type if you can, which is used if you don’t declare variables. This is why I’m using Option Explicit. You should too. 🙂

    There are probably a lot of ways to do what you want, but this is one:

    Option Explicit
    
    Function FindMin(AlphaVector)
        Dim iNew As Integer, i As Integer
        Dim iCount As Integer
        Dim Alpha() As Variant
    
        iCount = AlphaVector.Cells.Count
    
        '***** Use size of AlphaVector
        ReDim Alpha(0 To iCount - 1)
        iNew = 0
    
        For i = 1 To iCount
            '***** Only save values greater than 0
            If AlphaVector(i) > 0 Then
                Alpha(iNew) = AlphaVector(i)
                '***** Keep track of how many values you save
                iNew = iNew + 1
            End If
        Next i
    
        '***** Remove any empty items in the Alpha array
        ReDim Preserve Alpha(0 To iNew - 1)
    
        '***** Reture result of the Min function
        FindMin = WorksheetFunction.Min(Alpha)
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine I have array of values ranging from 1 to 24. I want to
I have array in following format. I want to convert it into another format
I have array that element is hash a = [{:history_date=>15/07/10}, {:open_price=>7.90}] I want to
I have array from serial read, named sensor_buffer . It contains 21 bytes. gyro_out_X=((sensor_buffer[1]<<8)+sensor_buffer[2]);
Suppose I have array of points.I want to draw the route of that points
I have array values of up[]={0,0,0,0,0} and view=adult thesetwo value i want to store
I have a PHP Array, and I want to extract from it the duplicated
I have array data as shown below, I want to store 'sale' value into
I would like to have array in numbering for days and months from starting
how make special random array. i have array(1=>35,2=>25,3=>40) . how make possibility that array

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.