4

約 50,000 行で構成されるデータセットがあり、各行 (またはセル) には値がコンマで区切られています。

item 1, item 2, item 1, item 1, item3, item 2, item 4, item3

目標出力は単純です

item 1, item 2, item3, item 4

Excel、Open Office Calc、notepad ++、またはその他の無料で利用できるプログラムを使用できます (JavaScript ソリューションを見つけましたが、それは単一の文字列用で、50,000 回実行しようとしてもうまくいかないか、私よりも時間がかかります)あり、それを調整するのに十分な JS を知りません)

これを行う方法に関する提案はありますか?

<一部のアイテムにスペースが含まれることに注意して編集>

4

1 に答える 1

4

始める必要があります。画面の更新と計算をオフにして、パフォーマンスを向上させます...

Sub Tester()

    Dim dict As Object
    Dim arrItems, c As Range, y As Long
    Dim val

    Set dict = CreateObject("scripting.dictionary")

    For Each c In ActiveSheet.Range("A1:A100").Cells

        arrItems = Split(c.Value, ",")
        dict.RemoveAll
        For y = LBound(arrItems) To UBound(arrItems)
            val = Trim(arrItems(y))
            If Not dict.exists(val) Then dict.Add val, 1
        Next y

        c.Offset(0, 1).Value = Join(ArraySort(dict.keys), ",")

    Next c

End Sub

キーを並べ替える場合:

Function ArraySort(MyArray As Variant)

    Dim First           As Integer
    Dim Last            As Integer
    Dim i               As Integer
    Dim j               As Integer
    Dim Temp

    First = LBound(MyArray)
    Last = UBound(MyArray)
    For i = First To Last - 1
        For j = i + 1 To Last
            If MyArray(i) > MyArray(j) Then
                Temp = MyArray(j)
                MyArray(j) = MyArray(i)
                MyArray(i) = Temp
            End If
        Next j
    Next i
    ArraySort = MyArray

End Function
于 2012-06-27T19:51:21.550 に答える