简体   繁体   English

如何在另一个单元格中将一个单元格值重复X次?

[英]How to repeat one cell value X times in another cell?

I have a sheet like this 我有一张这样的床单

在此处输入图片说明

How can I loop on column A based on column B and create comma separated entries ending with -0 , -1 .... in column C ? 如何能在专栏中,我环路A基于列B ,并创建以逗号分隔的结尾条目-0-1 ....列C

Use a UDF. 使用UDF。

Press Alt + F11 then right click in the Project column. Alt + F11,然后右键单击“ Project列。 Insert a new module and paste the code in module1. 插入一个新模块,并将代码粘贴到module1中。

Public Function textMul(ByVal target As String, ByVal n As Long) As String
    Dim tmpStr As String
    Dim i As Long
    For i = 1 To n
        If tmpStr <> "" Then tmpStr = tmpStr & ", "
        tmpStr = tmpStr & target & "-" & i - 1
    Next i
    textMul = tmpStr
End Function

Then back to your worksheet, typing textmul(A2,B2) generates the result. 然后回到您的工作表,键入textmul(A2,B2)生成结果。

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Excel:如何根据单元格值重复多个值 X 次,包括重复模式 - Excel: How to repeat multiple values based on a cell value X times, including a repeated pattern 如果另一个单元格是值X,则将一个单元格设置为另一个单元格的值 - Setting a cell to a value of another cell IF another cell was value X 如何在Excel中将一个单元格的值作为另一个单元格的位置 - How to make the value of one Cell as a position of another Cell in Excel VBA:CountIfS函数,用于计算多个工作表中单元格值为Yes的次数IF另一个单元格值 - VBA: CountIfS function to count how many times a cell value is Yes across multiple worksheets IF another cell value 如何在距离我所在的单元格X列的单元格中写入(X是在另一个单元格中定义的值) - How can I write in a cell that is X number of column away from the cell I am on (X is a value defined in another cell) 如何将一个单元格值映射到具有IF条件的另一个单元格 - How to map a cell value to another cell with IF condition 如何检查单元格的值是否为另一个单元格的子值 - How to check if value of cell is a subvalue of another cell 如何在Excel上将单元格值报告给另一个单元格 - How to report cell value to another cell on excel 如何将 2 个单元格值与 VBA 合并为一个单元格? - How to combine 2 cell value into one cell with VBA? 如何将一个单元格的值限制为另一个单元格的值? - How to limit the value of one cell's value by another cell's value?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM