+ Reply to Thread
Results 1 to 4 of 4

Developing a code that selects a correlation based on a ranking system of data inputs?

  1. #1
    Registered User
    Join Date
    06-06-2019
    Location
    Tulsa, Oklahoma
    MS-Off Ver
    Excel 2016
    Posts
    2

    Developing a code that selects a correlation based on a ranking system of data inputs?

    I'm trying to program a macro that will select a single correlation based on where data falls on the correlation's data range. I'm looking to select the correlation whose range midpoint is closest to my data point.

    For example, a few correlations are applicable for the following temperature data ranges:

    Correlation 1 - from 74 to 240 degrees Fahrenheit

    Correlation 2 - from 74 to 342 degrees Fahrenheit

    Correlation 3 - from 85 to 245 degrees Fahrenheit

    If I'm looking at a data point with 216 degrees F, the nearest applicable correlation would be Correlation 2, because the midpoint of its range is 208, which is closer than the other two.


    Of course, I'm trying to do this for tens of correlations and so doing it individually would be tiresome, and I already have a code written that will weed out correlations whose ranges are beyond my data.

    These correlations rely on a number of input parameters, and I would like to do this for all of the parameters. At the end, I would like to rank the correlations based on which correlation has the most parameters closest to the "midpoint" of their data ranges.

    This is, however, a different beast to conquer.

    For now, I'm just looking for help on how to rank the correlations by one parameter at a time.

    Any suggestions?

    Thanks so much!

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Developing a code that selects a correlation based on a ranking system of data inputs?

    This example makes liberal use of helper formulas. Columns A:C have your conditions (included the calculated mid-point). Columns G:L contain some generated sample data.

    Column G is the value
    Column H is the difference between the value and the first condition
    Column I is the difference between the value and the second condition
    Column J is the difference between the value and the third condition
    Column K is the minimum of these three values
    Column L uses INDEX and MATCH to find the column that contains the minimum and gets the appropriate condition from the header row.
    Attached Files Attached Files
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Registered User
    Join Date
    06-06-2019
    Location
    Tulsa, Oklahoma
    MS-Off Ver
    Excel 2016
    Posts
    2

    Re: Developing a code that selects a correlation based on a ranking system of data inputs?

    Thank you so much for this!! This helps a ton.

    I will be working with a very large spreadsheet full of data, however - I'm wondering if there's some way I can incorporate the "midpoint" of each correlation's data range combined with this Index function (or some VBA equivalent) into a macro so as to "clean up" the spreadsheet. Do you think this is possible?

    Thanks again!

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Developing a code that selects a correlation based on a ranking system of data inputs?

    I essentially combined all the formulas. You'll still need the mini-table in columns A,B and C. but you won't need the helper columns.

    =IF(ABS(G2-$D$2)=MIN(ABS(G2-$D$2),ABS(G2-$D$3),ABS(G2-$D$4)),"Case 1",IF(ABS(G2-$D$3)=MIN(ABS(G2-$D$2),ABS(G2-$D$3),ABS(G2-$D$4)),"Case 2","Case 3"))

    If you want to do away with the mini-table, you can "hard code" the actual numbers for D2, D3 and D4 in the formula.
    Attached Files Attached Files

+ 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. Filter and Sum based on inputs vba code
    By cgsierra in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-25-2018, 11:05 AM
  2. Replies: 7
    Last Post: 04-15-2018, 10:19 AM
  3. [SOLVED] VBA code that selects A3:L3 and then goes all the way down until there is no more data
    By rcdavis28 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-27-2018, 09:39 PM
  4. Developing a basic data base automation system!!
    By Absuuurrd in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 03-27-2015, 04:48 PM
  5. Replies: 0
    Last Post: 06-03-2014, 01:12 AM
  6. Automatic code creation based on two inputs
    By snezana in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-23-2013, 03:35 AM
  7. Code selects entire rows upto one range and same code selects only columns for other.
    By sriharigk in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-09-2012, 05:19 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