Solved

Math in Macro needs fix

Posted on 2013-12-05
12
182 Views
Last Modified: 2013-12-08
EE Pros,

I have a Risk/Return Macro and chart that when you put two variables into each cell in a row, it plots the appropriate point on the grid.  Here's the issue.  When you prioritize the list, (it sorts the descriptions, it doesn't properly calculate the sort.  In other words a Return of 8 and a Risk factor of 4 should take priority over a Return of 9 and a Risk factor of 6.

Look at the WS to see what I'm trying to accomplish.

Thank you in advance.

B.
Math-in-Macro-is-incorrect.xlsm
0
Comment
Question by:Bright01
  • 5
  • 4
  • 3
12 Comments
 
LVL 46

Expert Comment

by:Martin Liss
ID: 39699339
When I click the button nothing happens perhaps because I'm missing some links. What happens when you click the button and what should happen if it were working correctly.
0
 

Author Comment

by:Bright01
ID: 39699582
Marty,

Thanks for taking a look......  Change the values in col. C and D and then hit prioritize.  It will then stack rank the text in the order of priority.  The problem I have is that it seems to prioritize the first value but it doesn't seem to properly rank the other values.  A 5 on Return with a 5 on Risk should be higher up then a 5 on Return with a 6 on Risk.

Make sense?

B.
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 39699612
That formula is too complex for me to analyze but if you can describe the formula's logic in words, perhaps I can come up with a VBA solution.
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

Author Comment

by:Bright01
ID: 39699658
Much thanks.

So, I think the best way to look at this is that there are two axis's that scale in opposite directions.  What happens is that a description is put into Column B.  Then a Return value and a Risk value are placed into Columns C (Return) and Column D (Risk).  The higher the number (1-10) in the Return axis, the more value.  The lower the number (1-10) in the Risk axis (D), the more value.  So the most valuable combination would be 10 (C) and 1(D) while the lowest value would be a 1(C) and a 10(D).  With that as potentially an array, every combined value should be able to be prioritized (and reordered in Column B.  

You will see that the model actually works well.....EXCEPT for the fact that the math doesn't completely work.  In the example I sent you, the order should be B, C and A when the Prioritize macro is fired.

Make sense?

B.
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 39699689
If this isn't correct please tell me where the 1, 2 and 3 should go.
What's wrong?
0
 
LVL 81

Expert Comment

by:byundt
ID: 39699785
Your "ranking" formula in column E is favoring higher risk rather than lower risk because you are adding the value in D7:
=(C7*2)+D7

If you subtract the value in D7, then the formula will favor lower risk over higher risk:
=(C7*2)-D7
0
 

Author Comment

by:Bright01
ID: 39700754
Marty,

1 and 2 should be switched as they are prioritized.  1 has more value because while the return is =, the risk is lower. When that is determined, the graphic should show "1" as the best option and also have sorted the description and values in the table.

Make sense?

B.
0
 
LVL 81

Assisted Solution

by:byundt
byundt earned 250 total points
ID: 39700776
Bright01,
Did you try changing the formulas in column E as suggested? Your existing macro will work if you do that.

Brad
0
 
LVL 46

Accepted Solution

by:
Martin Liss earned 250 total points
ID: 39701077
1 has more value because while the return is =, the risk is lower.
Priority 2 has less risk (5) then Priority 1 (6), so shouldn't 2 be first?
0
 

Author Closing Comment

by:Bright01
ID: 39701961
Brad and Marty,

Thanks guys!  Based on the input you gave me, I was able to figure it out on my own!  

Here's what I ended up doing.  It was a long time ago that this graphic was made so I had missed the fact that I had a row hidden.  By unhiding the "helper" row, I changed the formula to =if(b="",0,(c + (10-d))) and it works perfectly when "priority" is fired.

Thanks again,

B.
0
 
LVL 81

Expert Comment

by:byundt
ID: 39701982
The original formula in column E weighted the Return twice as much as the Risk. Your revised formula assigns equal weighting to Return and Risk. Was this change in philosophy intentional?

From a ranking point of view, it doesn't matter whether you add the 10 or not. Even though the following two formulas return different results, they will make your rows sort exactly the same:
 =IF(b="",0,c + (10-d))
 =IF(b="",0,c-d)

The value returned by the first formula (on rows with data) will always be exactly 10 higher than the value returned by the second formula. This constant difference is why either formula can be used to rank your data for a sort.

Brad
0
 

Author Comment

by:Bright01
ID: 39705005
Brad,

Great comments!  I did want, in this instance, Risk and Return to be =.  Graphic looks pretty good now.

Thanks again,

b.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question