Results 1 to 4 of 4

Multiplying by 100 each cell in input range

Threaded View

  1. #1
    Registered User
    Join Date
    03-17-2014
    Location
    London, UK
    MS-Off Ver
    Excel 2010
    Posts
    26

    Multiplying by 100 each cell in input range

    EDIT: original post asked about adding values. Correct question regards multiplication.

    Hello everyone

    Here's a bit of VBA I found online to calculate a weighted median.

    Function WeightedMedian(ValueRange As Range, WeightRange As Range)
    
    Dim MedianArray()
    
    On Error GoTo WrongRanges
    
    ArrayLength = Application.Sum(WeightRange)
    ReDim MedianArray(1 To ArrayLength)
    
    Counter = 0
    ArrayCounter = 0
    
    For Each ValueRangeCell In ValueRange
    
    LoopCounter = LoopCounter + 1
    FirstArrayPos = ArrayCounter + 1
    ArrayCounter = ArrayCounter + Application.Index(WeightRange, LoopCounter)
    
    For n = FirstArrayPos To ArrayCounter
    
    MedianArray(n) = ValueRangeCell.Value
    
    Next
    
    Next
    
    WeightedMedian = Application.Median(MedianArray)
    Exit Function
    
    WrongRanges:
    WeightedMedian = CVErr(2016)
    End Function
    The code works nicely, except in cases where the cells in WeightRange are between 0 and 1. So it works fine if the cells in WeightRange are 1.0 and above, but the function returns a Value error if they WeightRange has anything like 0.6, 0.3, etc.

    Is there any way of multiplying 100 for each cell in WeightRange while the function runs? I have tried dropping in

    For WeightRangeCell In WeightRange
    WeightRangeCell = WeightRangeCell*100
    Next
    but it doesn't seem to do the trick (then again, I don't know VBA). Seems like something that ought to be simple enough.

    Unfortunately, adding a helper column is not an option, as I have hundreds of these weight ranges....

    Thanks in advance!
    Last edited by lucazzo; 02-17-2017 at 12:51 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Adding date on input in cell
    By Megashira in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-07-2014, 01:54 AM
  2. Replies: 3
    Last Post: 03-06-2013, 05:47 PM
  3. [SOLVED] Adding a range of numbers based on a numerical input
    By merlyn45 in forum Excel General
    Replies: 6
    Last Post: 06-21-2012, 04:43 PM
  4. [SOLVED] Adding color to a cell based on input value
    By cadamhill in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-03-2012, 10:15 AM
  5. Adding a Calendar for quick cell input
    By ImagineParidise in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-15-2012, 03:23 AM
  6. Adding input box number to range of cells values
    By Jessica in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-22-2006, 02:10 PM
  7. Problem adding input to cell
    By PghPatti in forum Excel General
    Replies: 6
    Last Post: 06-30-2005, 08:05 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