Yesterday, in the 30XL30D challenge, we took things easy, with the T function. For day 15 in the challenge, we'll examine the REPT function, which repeats a text string, a specified number of times. It's another Text function, and has a few interesting uses.
昨天,在30XL30D挑战赛中,我们使用T功能轻松完成任务。 在挑战的第15天,我们将检查REPT函数,该函数将文本字符串重复指定的次数。 这是另一个Text函数,有一些有趣的用途。
NOTE: You can have all of the 30 Functions content in an easy-to-use single reference file -- the 30 Excel Functions in 30 Days eBook Kit ($10).
注意:您可以在一个易于使用的单个参考文件中获得这30个函数的全部内容-30天电子书工具包中的30个Excel函数 (10美元)。
So, let's take a look at the REPT information and examples, and if you have other tips or examples, please share them in the comments.
因此,让我们看一下REPT信息和示例,如果还有其他提示或示例,请在评论中分享。
功能15:REPT (Function 15: REPT)
The REPT function repeats a text string, a specified number of times. The REPT function repeats a text string, a specified number of times. The REPT function repeats a text string, a specified number of times.
REPT函数将文本字符串重复指定的次数。 REPT函数将文本字符串重复指定的次数。 REPT函数将文本字符串重复指定的次数。
Note: Creating hilarious effects like the above paragraph would be much easier with the REPT function. 😉
注意 :使用REPT功能可以轻松创建类似于上一段的搞笑效果。 😉
![Rept00 Rept00](https://i-blog.csdnimg.cn/blog_migrate/1cadb143de6c00e04c04e697ff8d7bf7.png)
您如何使用REPT? (How Could You Use REPT?)
The REPT function can be used to fill a cell with a character, or in innovative ways, such as:
REPT函数可用于以字符填充单元格,或以创新的方式填充单元格,例如:
- Creating an in-cell bar or dot chart 创建单元内条形图或点状图
- Keeping a quick tally 保持快速统计
- Finding the last text entry in a column 查找列中的最后一个文本条目
REPT语法 (REPT Syntax)
The REPT function has the following syntax:
REPT函数具有以下语法:
-
- text is the item that you want to repeat. 文本是您要重复的项目。
- number_times is a positive number number_times是一个正数
REPT(text,number_times)
REPT(文本,number_times)
REPT陷阱 (REPT Traps)
- The limit to the text string is 32,767 characters -- anything higher, and the formula will result in an error. 文本字符串的限制是32,767个字符-更高的限制,该公式将导致错误。
- If number_times is a decimal, it will be truncated to an integer. 如果number_times是小数,它将被截断为整数。
- If number_times is zero, the result is an empty string. 如果number_times为零,则结果为空字符串。
REPT替代 (REPT Alternative)
If you simply want to fill a cell with a character, you can use cell formatting instead:
如果只想用字符填充单元格,则可以改用单元格格式:
- In a cell, type the character(s) that you want as the fill, e.g. a hyphen or period 在单元格中,键入要用作填充的字符,例如连字符或句号
- With the cell selected, press Ctrl + 1, to open the Format Cells window 选择单元格后,按Ctrl + 1,以打开“设置单元格格式”窗口
- Click the Alignment tab, and from the Horizontal setting, select Fill 单击“对齐”选项卡,然后从“水平”设置中选择“填充”
- Click OK to close the dialog box. 单击“确定”关闭对话框。
The character will fill the cell, and expands or shrinks as the column width is adjusted.
字符将填充单元格,并随着调整列宽而扩大或缩小。
![Rept00a Rept00a](https://i-blog.csdnimg.cn/blog_migrate/85d64fb930c7aa35d022b32abdc8ebdb.png)
示例1:单元内条形图 (Example 1: In-Cell Bar Chart)
If you don't have a newer version of Excel, with data bars, you can use the REPT function to create a simple in-cell bar chart. For example, to create a bar chart for a target of 100:
如果您没有带有数据条的Excel的较新版本,则可以使用REPT函数创建简单的单元格内条形图。 例如,要为目标100创建条形图:
- In cell B3, type 100 在单元格B3中,键入100
In cell C3, enter the following formula:
在单元格C3中,输入以下公式:
=REPT("n",B3/5)
= REPT(“ n”,B3 / 5)
- Format cell C3 with Wingdings font (I used font size 9) 使用Wingdings字体设置单元格C3的格式(我使用的是9号字体)
- Adjust column C's width to fit the resulting bar. 调整列C的宽度以适合生成的条。
- Change the number in cell B3, and the chart will change. 更改单元格B3中的数字,图表将更改。
I added conditional formatting in this example, to highlight quantities less than 60.
在此示例中,我添加了条件格式,以突出显示少于60的数量。
![Rept01 Rept01](https://i-blog.csdnimg.cn/blog_migrate/3c018377af2c66df34eb5c17aaeac5e3.png)
示例2:单元内点图 (Example 2: In-Cell Dot Chart)
Instead of bar charts, you can use the REPT function to create a simple in-cell dot chart. For example, to create a dot chart for a target of 100:
代替条形图,可以使用REPT函数创建简单的单元内点图。 例如,要为目标100创建点图:
- In cell B3, type 100 在单元格B3中,键入100
In cell C3, enter the following formula:
在单元格C3中,输入以下公式:
=REPT(" ",B3/5-1) & "o"
= REPT(“”,B3 / 5-1)&“ o”
- Adjust column C's width to fit the resulting bar. 调整列C的宽度以适合生成的条。
- Change the number in cell B3, and the dot location in the chart will change. 更改单元格B3中的数字,图表中的点位置将更改。
![Rept02 Rept02](https://i-blog.csdnimg.cn/blog_migrate/9f6ee81a182dc33329cfee004ab36a2c.png)
示例3:保持简单的提示 (Example 3: Keep a Simple Tally)
If you lost your cribbage board, or are counting the days until your next vacation, you can use a simple tally to keep track of the score, or the passing days.
如果您丢掉了记事板,或者正在计算直到下一个假期的天数,则可以使用简单的计数来跟踪得分或过去的日子。
![Rept03a Rept03a](https://i-blog.csdnimg.cn/blog_migrate/54122d1a80a7c4019f1f03600a688dc9.png)
To create a tally with the REPT function:
要使用REPT功能创建提示:
- In cell B3, type your target amount, e.g. 25 在单元格B3中,输入您的目标金额,例如25
In cell C3, enter the following formula:
在单元格C3中,输入以下公式:
=REPT("tttt ",INT(B3/5)) & REPT("l",MOD(B3,5))
= REPT(“ tttt”,INT(B3 / 5))和REPT(“ l”,MOD(B3,5))
- Format cell C3 with Comic Sans font, or another font with a straight "t". (Finally -- a use for Comic Sans!) 使用Comic Sans字体或带有直“ t”的另一种字体设置单元格C3的格式。 (最后-用于Comic Sans!)
- Adjust column C's width to fit the resulting bar. If the target number is high, you can increase the row height, and format for Wrap Text 调整列C的宽度以适合生成的条。 如果目标数字较高,则可以增加行高,并设置自动换行格式
- Change the number in cell B3, and the tally will change. 更改单元格B3中的数字,计数将更改。
The formula result shows one group of t's, for every 5 items in the count -- INT(B3/5).
公式结果显示了一组t,即计数中每5个项目INT(B3 / 5)。
If there is a remainder, after dividing the count by 5, that amount is displayed at the end, as lower case L's -- MOD(B3,5).
如果还有余数,则在将计数除以5后,最后将以小写L的形式显示该金额-MOD(B3,5)。
![Rept03b Rept03b](https://i-blog.csdnimg.cn/blog_migrate/af2dc3a7cf915ae9c44b348c5f73929a.png)
示例4:查找列中的最后一个文本项 (Example 4: Find the Last Text Item in a Column)
Combined with VLOOKUP, you can use the REPT function to find the last text item in a column. For example, with text items in column D, use this formula to find the last item:
与VLOOKUP结合使用,您可以使用REPT函数查找列中的最后一个文本项。 例如,对于D列中的文本项,请使用以下公式查找最后一项:
=VLOOKUP(REPT("z",255),D:D,1)
= VLOOKUP(REPT(“ z”,255),D:D,1)
The REPT function in the formula creates a text string at the end of the alphabet, and VLOOKUP won't be able to find that string. So, with approximate match, it returns the last text item in the list.
公式中的REPT函数会在字母的末尾创建一个文本字符串,而VLOOKUP将无法找到该字符串。 因此,通过近似匹配,它将返回列表中的最后一个文本项。
![Rept04 Rept04](https://i-blog.csdnimg.cn/blog_migrate/a159e4e43545a9cfce95565f0e490cd7.png)
下载REPT功能文件 (Download the REPT Function File)
To see the formulas used in today's examples, you can download the REPT function sample workbook. The file is zipped, and is in Excel 2007 file format.
要查看当前示例中使用的公式,可以下载REPT函数示例工作簿 。 该文件已压缩,并且为Excel 2007文件格式。
观看REPT视频 (Watch the REPT Video)
To see a demonstration of the examples in the REPT function sample workbook, you can watch this short Excel video tutorial.
要观看REPT函数示例工作簿中示例的演示,您可以观看这段简短的Excel视频教程。
翻译自: https://contexturesblog.com/archives/2011/01/16/30-excel-functions-in-30-days-15-rept/