+ Reply to Thread
Results 1 to 8 of 8

take user-defined array elements as a group?

Hybrid View

njs27 take user-defined array... 12-31-2015, 12:49 PM
Kenneth Hobson Re: take user-defined array... 12-31-2015, 01:34 PM
njs27 Re: take user-defined array... 12-31-2015, 01:44 PM
shg Re: take user-defined array... 12-31-2015, 02:04 PM
njs27 Re: take user-defined array... 12-31-2015, 02:58 PM
Kenneth Hobson Re: take user-defined array... 12-31-2015, 03:06 PM
shg Re: take user-defined array... 12-31-2015, 04:59 PM
Kenneth Hobson Re: take user-defined array... 12-31-2015, 06:52 PM
  1. #1
    Registered User
    Join Date
    08-12-2013
    Location
    USA
    MS-Off Ver
    Excel 2016, 32-bit
    Posts
    92

    take user-defined array elements as a group?

    I have a user-defined array with a number of elements. What I'm wondering is - is there an easy way to get the maximum value of one element for all the arrays?

    I have something like
    Type CustInfo
         Name as string
         Email as string
         Sales as double
    End Type
    and I want to find out what the largest number of Sales were for any single customer. Of course it would be nice to know the Customer's name as well, but I'll be happy to just get the sales number. Is there a way to do this without looping through the entire customer base, putting the sales # into an array and then finding the max of that array?

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: take user-defined array elements as a group?

    That is a user-defined data type, not an array. So, the value if any is the max.

  3. #3
    Registered User
    Join Date
    08-12-2013
    Location
    USA
    MS-Off Ver
    Excel 2016, 32-bit
    Posts
    92

    Re: take user-defined array elements as a group?

    Ok, it's a udt, not an array, but the question is still the same.

    I want to look at CustInfo(1).Sales, CustInfo(2).Sales, all the way through CustInfo(n).Sales. And of those values, find the largest one. Is there a way to do that?

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: take user-defined array elements as a group?

    Not without looping.
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Registered User
    Join Date
    08-12-2013
    Location
    USA
    MS-Off Ver
    Excel 2016, 32-bit
    Posts
    92

    Re: take user-defined array elements as a group?

    Quote Originally Posted by shg View Post
    Not without looping.
    Thanks, shg.

  6. #6
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: take user-defined array elements as a group?

    I don't see that as possible shg. If it was a collection then a loop could be used.
    Type CustInfo
         Name As String
         Email As String
         Sales As Double
    End Type
    
    Sub Main()
      Dim i As Integer, c As CustInfo
      For i = 1 To 3
        With c
          c.Sales = i
        End With
      Next i
      MsgBox c.Sales
      MsgBox c(1).Sales  'Error
    End Sub

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: take user-defined array elements as a group?

    Quote Originally Posted by Kenneth Hobson View Post
    I don't see that as possible shg. If it was a collection then a loop could be used.
    Pardon?

    Type uCustRecd
         Name As String
         Email As String
         Sales As Double
    End Type
    
    Sub Main()
      Const n As Long = 10
      Dim i As Long
      Dim auCust(1 To n) As uCustRecd
      Dim dMax As Double
      
      For i = 1 To n
        auCust(i).Sales = Rnd * 100
      Next i
      
      dMax = -1.79769313486231E+308
      For i = 1 To n
        If auCust(i).Sales > dMax Then dMax = auCust(i).Sales
      Next i
      
      Debug.Print dMax
    End Sub
    Last edited by shg; 01-04-2016 at 12:05 PM.

  8. #8
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: take user-defined array elements as a group?

    I have not used it that way, thanks for the example shg.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Please help with input form, arrays and a function
    By jbaich in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-20-2014, 01:50 PM
  2. [SOLVED] Convert Array set elements to Excel sheet and allow to user to add new data
    By Faridwahidi in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 10-16-2014, 06:11 PM
  3. [SOLVED] Removing specific elements from an Array based on matching elements in a different Array
    By jamesdeuce in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-24-2014, 10:35 PM
  4. Pass User-Defined Array
    By yawnzzzz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-16-2011, 05:20 AM
  5. Refer to array elements defined as Variant
    By hareleph in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-23-2011, 07:15 AM
  6. String array values to array of User-Defined Types
    By rtiltins in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-03-2008, 07:45 AM
  7. user defined function using Array
    By Dennisli2000 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-18-2007, 02:00 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1