Implement Excel multi-column data combination

Preface

Due to the work requirements of a good friend, it is necessary to realize the permutation and combination of three kinds of data on Excel. If using a programming language, it is nothing more than nested loops. However, it has not been implemented in Excel. After the implementation, I found it quite interesting and hereby record it for the convenience of follow-up. Engineer personnel can facilitate this requirement.

Effect preview

![![Insert image description here](https://img-blog.csdnimg.cn/e58a86d6a4cc496cbc9a1c6f650f17bd.png](https://img-blog.csdnimg.cn/586704f0bd8445db9f73ff38a6ca7b81.png

Things to know about Excel functions

COUNTA()
is used to count the number of non-empty cells in a column. COUNT() is commonly used, but it cannot handle statistics of non-numeric columns. This article is used to calculate the maximum value of a set.
For example, COUNTA(A:A), the rendering is subtracted by 1, so it is displayed as 3.

INDEX()
returns a specific cell value or reference in a given cell range. This article is used for assignment.
For example, INDEX(A:A, 2), the returned result is Shanghai.

ROW()
returns a referenced row number, which is used in this article to implement traversal.

MOD()
returns the remainder of the division of two numbers, which is used in this article to implement a recursive loop.

Implementation instructions

As shown in the results of the renderings

Function formula in column J: INDEX(A:A,(ROW(J2)-2)/($F$2 * $G$2) + 2) .

step official illustrate
0 ROW(J2)-2 Because we need to filter out the header and start from 0, we need - 2
1 $F$2 * $G$2 That is, the number of combinations of product name and accessories, that is, the number of cycles, 2 * 5
2 (ROW(J2)-2) / ($F$2 * $G$2) Take integers for classification and summarization
3 INDEX(A:A, (ROW(J2)-2) / ($F$2 * $G$2) + 2) Within the range of column A, + 2 is to ensure the correct value to filter out meaningless data, that is, A0, A1

In this way, the data in column I will successfully traverse 30 valid data (3 * 2 * 10) as shown below

K列的函数公式:=INDEX(B:B,MOD((ROW($J2)-2) / $G$2,$F$2) + 2)L列的函数公式:=INDEX(C:C,MOD(ROW($J2)-2)),$G$2) + 2)

The above formulas are generally similar. It should be noted that column K is / $G$2, and column L does not have / (which can be understood as / 1). This is the inconsistency in the corresponding number of loops, thus achieving nested loops in the program.

idea

It's a very interesting experience. You need to know the number of loops to prevent exceptions, and you need to use the $ symbol reasonably to ensure that horizontal expansion is supported. It is very simple from the perspective of implementation complexity, but compared to using a program to implement it, the former has a greater sense of accomplishment.

Guess you like

Origin blog.csdn.net/weixin_43832080/article/details/124831986