Sub 그룹별순번매기기()
Dim i As Long
Dim j As Long
Dim lastRow As Long
Dim currentRow As Long
Application.ScreenUpdating = False
If Range("B2") <> "" Then
Range("B2", Cells(Rows.count, "B").End(xlUp)).ClearContents
End If
lastRow = Cells(Rows.count, "A").End(xlUp).Row
For i = 0 + 2 To lastRow
count = 0
currentRow = i
For j = 0 + 2 To currentRow
If Cells(currentRow, "A") = Cells(j, "A") Then
count = count + 1
Cells(currentRow, "B") = Cells(j, "A") & "-" & count
End If
Next j
Next i
Application.ScreenUpdating = True
End Sub
Sub 그룹별순번매기기_배열()
Dim i As Long
Dim j As Long
Dim lastRow As Long
Dim currentRow As Long
Dim a()
Dim rngS
Dim count As Long
Application.ScreenUpdating = False
If Range("B2") <> "" Then
Range("B2", Cells(Rows.count, "B").End(xlUp)).ClearContents
End If
rngS = Range("A2", Cells(Rows.count, "A").End(xlUp))
lastRow = Cells(Rows.count, "A").End(xlUp).Row
ReDim Preserve a(UBound(rngS))
For i = 0 + 2 To lastRow
count = 0
currentRow = i
For j = 0 + 2 To currentRow
If Cells(currentRow, "A") = Cells(j, "A") Then
count = count + 1
a(j - 2) = Cells(j, "A") & "-" & count
' Cells(currentRow, "B") = Cells(j, "A") & "-" & Count
End If
Next j
Next i
Range("B2").Resize(UBound(a), 1) = Application.Transpose(a)
Application.ScreenUpdating = True
End Sub
'컴퓨터 > 엑셀' 카테고리의 다른 글
excel 열문자 표시하기, 파일이름, 워크시트이름,시트이름가져오기,cell (0) | 2022.11.17 |
---|---|
vba 배열원소 random 할당 (0) | 2022.05.05 |
vba 배열 (0) | 2022.05.01 |
vba 순번매기기 (0) | 2022.04.29 |
vba 여러셀 기호 넣어 셀합치기, 셀나누기 (0) | 2022.04.14 |