스터디내용

Rows.count & Columns.count 이용 마지막 행, 열 찾기

Vㅇㅅㅇ V 2023. 10. 12. 12:41

Rows.count로 마지막 행찾는 예제

Sub FindLastRow()
    Dim lastRow As Long

    ' 마지막 행 찾기
    lastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row

    ' 마지막 행에 숫자 입력
    Range("A" & lastRow + 1).Value = 10
End Sub

Columns.count로 마지막 열찾는 예제

Sub FindLastColumn()
    Dim lastColumn As Long

    ' 마지막 열 찾기
    lastColumn = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column

    ' 마지막 열에 숫자 입력
    Cells(1, lastColumn + 1).Value = 10
End Sub