0
0

More than 3 years have passed since last update.

グループごとに連番振り分け

Posted at

連番振分

<処理機能>

C列の値をグループごとにし、A列に親連番、B列に子連番を振り分ける機能

<実行の前提条件>

・C列がソートされていること

Sub addseq()
    Dim lng_i As Long
    Dim lng_j As Long
    Dim i As Long
    Dim iMax As Long

    iMax = 137934

    Range("A" & 1) = "親SEQ"
    Range("B" & 1) = "子SEQ"

    lng_i = 0
    lng_j = 0
    For i = 2 To iMax Step 1
        If Range("C" & (i)).Value <> Range("C" & (i - 1)).Value Then
            '親番号振り分け
            lng_i = lng_i + 1
            lng_j = 1
        Else
       '子番号振り分け
            lng_j = lng_j + 1
        End If

        Range("A" & i) = lng_i
        Range("B" & i) = lng_j
    Next
End Sub

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0