컴퓨터/엑셀
vba 값이 없는 범위 시트 순환하면서 삭제하기 - 용량 줄이기
풍경소리^^
2024. 8. 8. 15:32
https://www.youtube.com/watch?v=ir34z3c1IL8
Sub row_col_delete_chatGPT()
Dim lngSrow As Long
Dim lngScol As Long
Dim Ws As Worksheet
Application.Calculation = xlCalculationManual '수동계산
For Each Ws In Worksheets
Ws.Activate
With Ws.UsedRange
' 데이터가 있는 마지막 행을 찾고, 그 다음 행부터 마지막 행까지 삭제
lngSrow = .Find("*", .Cells(1, 1), , , xlByRows, xlPrevious).Row + 1
Ws.Rows(lngSrow & ":" & Rows.Count).Delete xlUp
' 데이터가 있는 마지막 열을 찾고, 그 다음 열부터 마지막 열까지 삭제
lngScol = .Find("*", .Cells(1, 1), , , xlByColumns, xlPrevious).Column + 1
' 알파벳으로 변환된 열 참조를 사용해 삭제
If lngScol <= Columns.Count Then
Ws.Range(Columns(lngScol).Address & ":" & Columns(Columns.Count).Address).Delete xlToLeft
End If
End With
Next Ws
Application.Calculation = xlCalculationAutomatic '자동계산
End Sub