30天中30个Excel函数:15 – REPT

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

您如何使用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:

如果只想用字符填充单元格,则可以改用单元格格式:

  1. In a cell, type the character(s) that you want as the fill, e.g. a hyphen or period

    在单元格中,键入要用作填充的字符,例如连字符或句号
  2. With the cell selected, press Ctrl + 1, to open the Format Cells window

    选择单元格后,按Ctrl + 1,以打开“设置单元格格式”窗口
  3. Click the Alignment tab, and from the Horizontal setting, select Fill

    单击“对齐”选项卡,然后从“水平”设置中选择“填充”
  4. Click OK to close the dialog box.

    单击“确定”关闭对话框。

The character will fill the cell, and expands or shrinks as the column width is adjusted.

字符将填充单元格,并随着调整列宽而扩大或缩小。

Rept00a

示例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创建条形图:

  1. In cell B3, type 100

    在单元格B3中,键入100
  2. In cell C3, enter the following formula:

    在单元格C3中,输入以下公式:

    =REPT("n",B3/5)

    = REPT(“ n”,B3 / 5)

  3. Format cell C3 with Wingdings font (I used font size 9)

    使用Wingdings字体设置单元格C3的格式(我使用的是9号字体)
  4. Adjust column C's width to fit the resulting bar.

    调整列C的宽度以适合生成的条。
  5. 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

示例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创建点图:

  1. In cell B3, type 100

    在单元格B3中,键入100
  2. In cell C3, enter the following formula:

    在单元格C3中,输入以下公式:

    =REPT(" ",B3/5-1) & "o"

    = REPT(“”,B3 / 5-1)&“ o”

  3. Adjust column C's width to fit the resulting bar.

    调整列C的宽度以适合生成的条。
  4. Change the number in cell B3, and the dot location in the chart will change.

    更改单元格B3中的数字,图表中的点位置将更改。
Rept02

示例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

To create a tally with the REPT function:

要使用REPT功能创建提示:

  1. In cell B3, type your target amount, e.g. 25

    在单元格B3中,输入您的目标金额,例如25
  2. 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))

  3. 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!)
  4. 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的宽度以适合生成的条。 如果目标数字较高,则可以增加行高,并设置自动换行格式
  5. 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

示例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

下载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/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值