


Let's analyze how Excel uses functions to find combinations that sum to a certain value.
本篇文章给大家带来了关于excel的相关知识,其中主要介绍了如何使用函数寻找总和为某个值的组合的问题,下面就来看一下,希望对大家有帮助。
相关学习推荐:excel教程
今天给大家分享一下如何使用函数寻找总和为某个值的组合。
举个例子。
如下图所示,A~B列是数据源,A列是发票号,B列是发票金额。现在需要寻找总和为F1单元格指定值,比如20,089的发票组合。
关于这个问题,很久以前给大家分享过规划求解的方法;今天再给大家分享一下函数的方法。
在C2单元格输入以下公式,并复制到C2:C21区域。
=IF(SUM(C$2:C$21)=F$1,C2,B2*RANDBETWEEN(0,1))
公式输入后系统会提示循环引用,这是由于公式引用了公式所在单元格的值,不过别管他,谁稀罕爱她。
依次点击Excel左上角的「文件」→「选项」命令,打开文件选项对话框,切换到「公式」选项卡,选中「启动迭代计算」复选框,将「最多迭代次数」设置为30000。「确定」后关闭对话框。
此时C列公式会自动重算,重算结果非0的项即为发票组合。可以在F2单元格输入一个SUM函数公式进行验证。
给大家解释一下公式的意思。
=IF(SUM(C$2:C$21)=F$1,C2,B2*RANDBETWEEN(0,1))
公式首先判断C2:C21区域的总和是否等于F1单元格指定的目标值,如果相等,则返回C2自身的值,否则,返回B2单元格发票金额乘以0或1。当乘以0时,结果返回0,表示该发票金额未被选中,当乘以1时,返回发票金额自身,表示被选中。
由于公式引用了公式所在单元格的值,比如C2单元格的公式SUM(C$2:C$21),也就会触发循环引用。此时我们启用迭代计算,系统会反复计算该公式,直至停止迭代的条件成立(C2:C21的总和等于目标值),或迭代次数用尽。
就这么回事。
最后留个练习题。
如上图所示,已知总和25,由10个数值构成,每个数值大于等于1,且小于等于5,请列出这10个数值的任一组合。
参考答案:
A3:A12输入公式
=IF(SUM(A$3:A$12)=B$1,A3,RANDBETWEEN(1,5))
相关学习推荐:excel教程
The above is the detailed content of Let's analyze how Excel uses functions to find combinations that sum to a certain value.. For more information, please follow other related articles on the PHP Chinese website!

This tutorial explains how to calculate the median of numerical data in Excel using the MEDIAN function. The median, a key measure of central tendency, identifies the middle value in a dataset, offering a more robust representation of central tenden

Master Google Sheets COUNTIF: A Comprehensive Guide This guide explores the versatile COUNTIF function in Google Sheets, demonstrating its applications beyond simple cell counting. We'll cover various scenarios, from exact and partial matches to han

This tutorial provides a comprehensive guide to sharing Excel workbooks, covering various methods, access control, and conflict resolution. Modern Excel versions (2010, 2013, 2016, and later) simplify collaborative editing, eliminating the need to m

This tutorial explores various methods for converting .xls files to .jpg images, encompassing both built-in Windows tools and free online converters. Need to create a presentation, share spreadsheet data securely, or design a document? Converting yo

This tutorial clarifies the function of Excel names and demonstrates how to define names for cells, ranges, constants, or formulas. It also covers editing, filtering, and deleting defined names. Excel names, while incredibly useful, are often overlo

This tutorial clarifies the distinction between standard deviation and standard error of the mean, guiding you on the optimal Excel functions for standard deviation calculations. In descriptive statistics, the mean and standard deviation are intrinsi

This Excel tutorial demonstrates how to calculate square roots and nth roots. Finding the square root is a common mathematical operation, and Excel offers several methods. Methods for Calculating Square Roots in Excel: Using the SQRT Function: The

Unlock the Power of Google Sheets: A Beginner's Guide This tutorial introduces the fundamentals of Google Sheets, a powerful and versatile alternative to MS Excel. Learn how to effortlessly manage spreadsheets, leverage key features, and collaborate


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Chinese version
Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool