vba 순번매기기
Sub 순번매기기()
Dim rngErase As Range
Dim lastRow As Long
Dim rngT As Range
Dim C As Range
Dim i As Long
Set rngErase = Range("B2", Cells(Rows.Count, "B").End(xlUp)) '순번 범위
rngErase.ClearContents '초기화
lastRow = Cells(Rows.Count, "A").End(xlUp).Row '기준열의 마지막 행
Set rngT = Range("B2", Cells(lastRow, "B")) 'target 열
For Each C In rngT
i = i + 1
C = i
Next C
End Sub
===============
Sub 배열번호매기기()
Dim rngErase As Range
Dim rngS
Dim i As Long
Dim columnS As String
Dim columnT As String
Dim arr()
columnS = "A" '기준 열
columnT = "E" '순번 열
If Cells(Rows.Count, columnT).End(xlUp) <> "순번" Then
Set rngErase = Range(Cells(2, columnT), Cells(Rows.Count, columnT).End(xlUp)) '순번 열
rngErase.ClearContents '초기화
End If
rngS = Range(Cells(2, columnS), Cells(Rows.Count, columnS).End(xlUp))
ReDim arr(UBound(rngS))
For i = 1 To UBound(rngS)
arr(i - 1) = i
Next i
Cells(2, columnT).Resize(UBound(arr)) = Application.Transpose(arr)
Erase arr
End Sub