+ Reply to Thread
Results 1 to 6 of 6

Finding 10 largest/smallest values and populating another tab

Hybrid View

bigjdawg43 Finding 10 largest/smallest... 07-20-2020, 12:06 AM
FDibbins Re: Finding 10... 07-20-2020, 12:44 AM
bigjdawg43 Re: Finding 10... 07-20-2020, 12:54 AM
bigjdawg43 Re: Finding 10... 07-20-2020, 12:56 AM
bigjdawg43 Re: Finding 10... 07-20-2020, 05:04 PM
bigjdawg43 Re: Finding 10... 07-20-2020, 09:28 PM
  1. #1
    Forum Contributor
    Join Date
    06-30-2017
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2013
    Posts
    251

    Finding 10 largest/smallest values and populating another tab

    Earlier today, someone helped me out with the below code, and i was VERY appreciative.

    The idea is to find the rows of the 10 largest values in a column (x in the below code), and for each value/row, grab other information in the same row from other columns and populate another tab (Source1Y) with that info (that's the part with the use of Resize and Array). The problem is that I forgot to continue the conversation as to how to do the same exact thing, but also with the 10 smallest values in a column (my proposed y in the code below). I can attach a workbook if need be, but i have a feeling this is pretty easy to do, I just can't seem to figure it out.

    So conceptually, i'd need

      .Range("C" & nr).Resize(, 6) = Array(ws.Range("A" & x), ws.Range("B" & x), ws.Range("C" & x), ws.Range("DT" & x), ws.Range("DU" & x), ws.Range("EB" & x))
    for both x and y. What's the best way to do this? Appreciate any help. Thanks!

    Dim ws As Worksheet
    Dim AWF As WorksheetFunction
    Dim i As Long, nr As Long, x As Long, y As Long
    
    Application.ScreenUpdating = False
    Set AWF = Application.WorksheetFunction
    
    'Calculate 1Y contributors
    
    For Each ws In ThisWorkbook.Sheets
        If ws.Name = "Port1" Or _
           ws.Name = "Port2" Then
            With ws
                For i = 1 To 10
                    x = AWF.Match(AWF.Large(.Range("EB:EB"), i), .Range("EB:EB"), 0)
                    y = AWF.Match(AWF.Small(.Range("EB:EB"), i), .Range("EB:EB"), 0)
                    Debug.Print x
                    Debug.Print y
                        With Sheets("Source1Y")
                            nr = .Cells(.Rows.Count, 3).End(xlUp).Row + 1
                            .Range("C" & nr).Resize(, 6) = Array(ws.Range("A" & x), ws.Range("B" & x), ws.Range("C" & x), ws.Range("DT" & x), ws.Range("DU" & x), ws.Range("EB" & x))
                        End With
                Next i
            End With
        End If
    Next ws
    
    End Sub

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,053

    Re: Finding 10 largest/smallest values and populating another tab

    Not really sure why you need VBA for this, INDEX/MATCH/SMALL(large) will do the same thing for you
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Forum Contributor
    Join Date
    06-30-2017
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2013
    Posts
    251

    Re: Finding 10 largest/smallest values and populating another tab

    Right, it's part of a much larger workbook/process and was hoping to have it done programmatically. Think it's right there, just having issues with populating both large and small in the process.

  4. #4
    Forum Contributor
    Join Date
    06-30-2017
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2013
    Posts
    251

    Re: Finding 10 largest/smallest values and populating another tab

    To use INDEX/MATCH/SMALL(LARGE), i'd have to invoke INDIRECT to capture the correct tabs and that whole structure would be a mess for anybody using it other than me

  5. #5
    Forum Contributor
    Join Date
    06-30-2017
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2013
    Posts
    251

    Re: Finding 10 largest/smallest values and populating another tab

    Anybody have any ideas?

  6. #6
    Forum Contributor
    Join Date
    06-30-2017
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2013
    Posts
    251

    Re: Finding 10 largest/smallest values and populating another tab

    Figured this out. Kind of clunky, but separate loop for largest and smallest.

+ 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. [SOLVED] Finding and reporting largest and smallest from a fixed table
    By sungen99 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 03-20-2019, 12:08 PM
  2. return values but ranked largest to smallest
    By Nicfrenchy in forum Excel General
    Replies: 1
    Last Post: 08-24-2017, 06:08 AM
  3. Filtering SUMIFS values largest to smallest
    By sbeatty in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-07-2017, 02:56 AM
  4. [SOLVED] How can I short values smallest to largest with below formula
    By rajeshn_in in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 11-07-2016, 08:34 AM
  5. Finding smallest and largest gaps in list of dates.
    By ajay1965 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 02-20-2016, 04:04 PM
  6. [SOLVED] Extracting Smallest and Largest Values from a Column
    By drw53 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 02-12-2014, 02:58 PM
  7. Returning the Nth Largest / Smallest Values in a Range
    By ExcelTip in forum Tips and Tutorials
    Replies: 0
    Last Post: 08-29-2005, 07:53 AM

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