简体   繁体   English

如何将数字添加到Excel单元格?

[英]How can I add numbers to a excel cell?

I have a list of 100 names in column A. For example John, Jacob, James. 我在A列中列出了100个名称。例如John,Jacob,James。

I would like to add the numbers 1-99999 to each cell in column A. 我想将数字1-99999添加到A列的每个单元格中。

I have the list of numbers, how can I add them to each cell to output like this ? 我有数字列表,如何将它们添加到每个像元中以进行输出? John1 John2 John3 ... Jacob1 Jacob2 Jacob3 约翰1约翰2约翰3 ...雅各布1雅各布2雅各布3

如果将以下公式放在单元格B1中并向下复制大约一百万行,则应获得所需的答案:

=INDEX(A:A, INT((ROW() - 1) / 99999) + 1) & (MOD(ROW() - 1, 99999) + 1)

This is a comment on copying down as an answer as I don't have enough reputation 这是评论,因为我没有足够的声誉而抄写下来作为答案

if you place the formula provided by Phylogenesis in to the first cell in the column next to the column with your data the move your mouse to the bottom right hand corner of the highlighted cell the cursor will change in to a cross. 如果将“系统发育”提供的公式放置在包含数据的列旁边的第一个单元格中,则将鼠标移至突出显示的单元格的右下角,光标将变为十字形。 Double click the mouse and this will automatically add the formula to all the appropriate cells - assuming there are no blanks 双击鼠标,这将自动将公式添加到所有适当的单元格中(假设没有空格)

Try this small macro: 试试这个小宏:

Sub NumberNames()
    Dim jacob As Long, john As Long, james As Long
    Dim i As Long
    jacob = 1
    james = 1
    john = 1
    For i = 1 To 100
        With Cells(i, 1)
            v = .Value
            If v = "John" Then
                .Value = .Value & john
                john = john + 1
            End If
            If v = "Jacob" Then
                .Value = .Value & jacob
                jacob = jacob + 1
            End If
            If v = "James" Then
                .Value = .Value & james
                james = james + 1
            End If
        End With
    Next i
End Sub

if your data starts out like: 如果您的数据像这样开始:

James
Jacob
John
James
John
John
James
John
James
John
Jacob
John
James
James
John
John
James
John
James
James

it will end up like: 它最终将像:

James1
Jacob1
John1
James2
John2
John3
James3
John4
James4
John5
Jacob2
John6
James5
James6
John7
John8
James7
John9
James8
James9

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM