2016-12-05 121 views
-2

我需要在第一列(A2)的第二行写入该数据,然后自动填充直到电子表格的末尾。如果使用动态范围连接+计数

=CONCATENATE(D1;".";COUNTIF($D$1:D1, D1))

的最前一页“D1”需要是固定的,因为在第二行的代码必须是“=CONCATENATE(D1;".";COUNTIF($D$1:D2, D2))

及其大量的数据的和Excel不会由式处理,所以我需要用VBA来做。

我想要做的事:

我有多次出现的名单。我需要用它迄今出现的次数来写这个名字。例如:

Miriam -- Miriam.1 
Maria -- Maria.1 
Thiago -- Thiago.1 
Maria -- Maria.2 
Cloe -- Cloe.1 
Maria -- Maria.3 

任何人都可以帮助我吗?

+0

你是什么意思,“Excel将无法按公式处理它“?你有错误吗?您是否尝试过将公式向下拖动或将其粘贴到范围内? – Chrismas007

+0

我的意思是spreedsheet有1048576行,所以当我尝试向下拖动公式时,它只是崩溃! –

+0

对不起,我的英语,顺便说一句! –

回答

1

假设A2 =“= CONCATENATE(D2;”。“; COUNTIF($ D $ 1:D2,D2))” and A3 =“= CONCATENATE(D3;”。“; COUNTIF($ D $ 1:D3 ,D3))”

试试这个,100K运行在几分钟 1048576后18分钟

仍然在运行,如果你是绝望的,你可以在批量运行这个数据

LASTROW = 100000 ,因为i = 2 to lastrow

lastrow = 200000,对于i = 100001到LASTROW

等 我认为有足够的时间将在64位办公室2016年4GB内存运行一次全部

IM BTW。

Sub test() 

Dim namerange As Range 
Dim countrange As Range 
Dim i As Double 
Dim lastrow As Double 
lastrow = 50000 

Set namerange = Sheet1.Range("D1:D" & 1048576) 
Set countrange = Sheet1.Range("A1:A" & 1048576) 

For i = 2 To lastrow 

    countrange(i, 1) = namerange(i, 1) & "." & _ 
Application.WorksheetFunction.CountIf(namerange.Range("A1:A" & i), namerange(i, 1)) 

Next i 

Sheet1.Range("A1").Resize(countrange.Rows.Count, 1).Cells.Value = countrange.Cells.Value 
End Sub 
+0

非常感谢! 它的工作! –

+0

仪嗨,很好听 –

+0

任何你能记住我的答案与记号 –

1

奔跑在90秒内完整列表, 依赖于E栏是空白的,这会破坏E列的任何数据

Option Explicit 

Sub test() 
    Application.ScreenUpdating = False 
    Application.DisplayAlerts = False 

    Dim temprange As Range 
    Dim i As Double 
    Dim nameCounter As Integer 
    Dim lastrow As Double 
    lastrow = 1048576 
    nameCounter = 1 
    Set temprange = Sheet1.Range("A1:D" & lastrow) 
    For i = 2 To lastrow 
     temprange(i, 5) = i 
    Next i 

    temprange.Range(Cells(1, 1), Cells(lastrow, 5)).Sort Key1:=Cells(1, 4), Order1:=xlAscending, _ 
     Key2:=Cells(1, 5), Order1:=xlAscending, Header:=xlYes 

    For i = 2 To lastrow 
     If temprange(i, 4) <> temprange(i - 1, 4) Then 
      nameCounter = 1 
     Else 
      nameCounter = nameCounter + 1 
     End If 
     temprange(i, 1) = temprange(i, 4) & "." & nameCounter 
    Next i 
    temprange.Range(Cells(1, 1), Cells(lastrow, 5)).Sort Key1:=Cells(1, 5), Order1:=xlAscending, Header:=xlYes 
    temprange.Columns(5).Clear 

    Application.ScreenUpdating = True 
    Application.DisplayAlerts = True 

End Sub