Results 1 to 5 of 5

how to calculate median in vba excel scripting dictionary

Threaded View

  1. #1
    Registered User
    Join Date
    08-10-2016
    Location
    Ireland
    MS-Off Ver
    2013
    Posts
    67

    how to calculate median in vba excel scripting dictionary

    Hi folks,

    I have the below vba code which is calculating the sum of quantity against the items on click of the button from the "data" sheet and populate the results onto the "output" sheet. I need to calculate the median price also but struggling to do so. Can someone help on this please? I am attaching the sample data with code for your easy reference. Thanks in advance...

    Sub Test()
        Dim vT, v
        Dim i As Long, ndx As Long, d As Object
        Dim t As Double, tp As Double
        
        vT = Range("Data!A1").CurrentRegion.Value2
        Set d = CreateObject("Scripting.Dictionary")
        
        With Worksheets("Output")
            .Cells(1, 1).CurrentRegion.Offset(1).Clear
            
            'Item and Descriptions
            For i = 2 To UBound(vT)
                d.Item(vT(i, 1)) = vT(i, 2)
            Next i
            .Cells(2, 1).Resize(d.Count) = Application.Transpose(d.keys)
            .Cells(2, 2).Resize(d.Count) = Application.Transpose(d.items)
            
            ReDim v(1 To d.Count, 1 To 5)
            tp = 0
            For i = 2 To UBound(vT)
                ndx = Application.Match(vT(i, 1), d.keys, 0)
                v(ndx, 1) = v(ndx, 1) + vT(i, 3)    'Quantity
            Next
            d.RemoveAll
            
            .Cells(2, 3).Resize(UBound(v, 1), UBound(v, 2)).Value = v
            
            With .UsedRange
                .Columns("A").NumberFormat = "@"
                .Columns("B").NumberFormat = "#,##0"
                .Columns("C").NumberFormat = "@"
                .Columns("D").NumberFormat = "$* #,##0.00"
            End With
        End With
    End Sub
    Thanks,
    Abhi
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. scripting dictionary
    By madhukar37 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-15-2018, 06:13 AM
  2. [SOLVED] Dictionary or Scripting.Dictionary. Binding Referencing Dim-ing. Sub routines and Function
    By Doc.AElstein in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 07-12-2016, 08:28 AM
  3. Scripting dictionary help
    By leanne2011 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 11-14-2014, 09:51 AM
  4. need help with scripting dictionary
    By leanne2011 in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 10-04-2014, 04:33 PM
  5. Scripting Dictionary
    By Tendla in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-20-2013, 05:41 AM
  6. [SOLVED] Add & calculate Values in Scripting.Dictionary
    By girish.talele in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-21-2012, 06:32 AM
  7. [SOLVED] Scripting Dictionary help
    By williams485 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-13-2012, 08:22 AM

Tags for this Thread

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