컴퓨터/엑셀

행번호매기기

풍경소리^^ 2018. 6. 3. 15:29

Sub 행값매기기()
Dim r As Range
Dim rng As Range
Dim rowsCnt As Long
Dim k As Variant
     Set r = Range(Cells(2, "ag"), Cells(Rows.Count, "AG").End(3))
     rowsCnt = Cells(Rows.Count, 33).End(3).Row
     Set rng = Range(Cells(2, "ah"), Cells(rowsCnt, "ah"))
   
Range(Cells(2, "ah"), Cells(Rows.Count, "ah")).ClearContents
Cells(2, "ah").Select
Application.ScreenUpdating = False
For Each k In rng

    If Cells(ActiveCell.Row, ActiveCell.Column - 1).Value <> "" Then

    Cells(ActiveCell.Row, "AH").Formula = "=ROW()-1"

    Cells(ActiveCell.Row + 1, ActiveCell.Column).Select
End If


Next k
Application.ScreenUpdating = True
End Sub


버전업========== ========== ========== ========== ==========


Sub 행값매기기()

Dim rng As Range

Dim rowsCnt As Integer

    rowsCnt = Cells(Rows.Count, "ag").End(3).Row

    Set rng = Range(Cells(2, "ah"), Cells(rowsCnt, "ah"))

    Range(Cells(2, "ah"), Cells(Rows.Count, "ah")).ClearContents

    

    rng.Formula = "=ROW()-1"

    rng.Select

    Selection.Copy

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

        :=False, Transpose:=False

    Application.CutCopyMode = False

    Cells(2, "ah").Select

End Sub