Excel 中具有非标准间隔的复杂舍入
我需要将计算出的数字四舍五入到表中最接近的值。表中的值不连续,并且值之间的间隔也不相同。 (实际上我无法找到这些值之间的模式。)
以下是表值:
1
10
20
40
70
120
180
260
360
610
940
1350
1780
2220
2720
3490
4770
6500
8070
10000
例如,如果我计算出的数字为 53.36
,则公式应返回一个表值40
。如果该值高于 55
,则返回 70
。
I need to round a calculated number to the closest value in a table. The values in the table are not sequential, and the intervals between the values are not the same. (I actually haven't been able to find a pattern between the values.)
Here are the table values:
1
10
20
40
70
120
180
260
360
610
940
1350
1780
2220
2720
3490
4770
6500
8070
10000
So for instance, if I have a calculated number of 53.36
, the formula should return a table value of 40
. If the value was above 55
, then it would return 70
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用最终参数为 1 或 true(不完全匹配)的 vlookup。
将您的值放在一个范围内,然后在该范围内进行查找。它将找到不大于搜索值的最接近的值。
编辑:
顺便说一句,您列出的数字是穆迪在债券评级中使用的WARF(加权平均评级因子)数字。参见这里。
编辑#2:要获得您要查找的“四舍五入”,只需在搜索范围中添加第二列,其中包含下一个数字。例如:在20所在行,第二列将显示40;在 40 的行上,第二列将显示 70。然后,在您的公式中,在同一搜索范围上进行第二次 vlookup,但返回第二列。获得两个数字(示例值 55 为 40 和 70)后,您可以在公式中进行数学计算以确定要显示的数字。
Use vlookup with a final parameter of 1 or true (not exact match).
Put your values in a range and vlookup on that range. It will find the nearest value that is not greater than the search value.
Edit:
And...by the way, your numbers listed are WARF (weighted average rating factor) numbers used by Moody's in rating bonds. See here.
Edit #2: To get the "rounding up" you're looking for, just have a second column in your search range that has the next number up. E.g.: On the row where 20 is, the second column would show 40; on the row for 40, the second column would show 70. Then, in your formula, hava second vlookup on the same search range, but returning the second column. Once you've got the two numbers (40 and 70 for your example value of 55), you can do the math in your formula to determine which you'll show.
使用 VBA 应该是一个快速且简单的 if then 循环。检查您的号码与列表中接下来的 2 个号码之间的差异。当第一个数字的差异较小时,您就知道这就是您想要返回的数字。
Should be a quick and easy if then loop using VBA. Check the difference between your number and the next 2 numbers in the list. When the difference is less with the first number you know that's the one you want to return.
您可能需要考虑一个数组函数(又名 CSE 函数)。如果您的表格位于 A1:A20 范围内,并且您的查找值位于 C1 中,则使用此功能:
然后按 Control-Shift-Enter(不仅仅是 Enter)。
基本上,这会找到 C1 与表中任何值之间的最小绝对差。然后它尝试添加它并执行 VLOOKUP 以查看它是否在表中,如果失败,它会减去它并执行 VLOOKUP。有点复杂,但可能会给你一些想法。
You might want to think about an Array function (aka CSE Function). If your table is in range A1:A20, and your lookup value is in C1, then use this function:
and then Control-Shift-Enter (not just Enter).
Basically, this finds the minimum absolute difference between C1 and any value in your table. Then it tries adding it and doing a VLOOKUP to see if it's in the table, if that fails, it subtracts it and does VLOOKUP. A little complicated, but might give you ideas.