programing

Excel through vba에서 행 전체가 공백인지 확인하는 방법

bestprogram 2023. 4. 17. 22:35

Excel through vba에서 행 전체가 공백인지 확인하는 방법

저는 두 가지 다른 출처의 데이터를 가지고 있는 시트를 가지고 있습니다.나는 그들 사이에 아무것도 없다.이 빈 행을 구분 기호로 지정합니다.행 전체가 공백인지 아닌지는 어떻게 알 수 있습니까?

행 전체를 리터럴로 말하고 있는 경우는, 다음과 같은 코드가 동작합니다(셀에 수식이나 공백이 존재하지 않는 한).

If Application.CountA(ActiveCell.EntireRow)=0 Then
     MsgBox "Row Empty"
     Exit Sub
End If

그렇지 않은 경우 행의 범위에 대해 다음을 수행합니다.

Dim neValues As Range, neFormulas As Range, MyRange As Range

Set MyRange = Columns("C:AA")

On Error Resume Next
Set neValues = Intersect(ActiveCell.EntireRow.SpecialCells(xlConstants), MyRange)
Set neFormulas = Intersect(ActiveCell.EntireRow.SpecialCells(xlFormulas), MyRange)
On Error GoTo 0

If neValues Is Nothing And neFormulas Is Nothing Then
    MsgBox "Nothing There"
Else
    MsgBox "Something's There"
End If

(출처 : http://www.ozgrid.com/forum/showthread.php?t=26509&page=1)

WorksheetFunction.CountA()(아래 그림 참조):

Dim row As Range
Dim sheet As Worksheet
Set sheet = ActiveSheet

For i = 1 To sheet.UsedRange.Rows.Count

    Set row = sheet.Rows(i)
    If WorksheetFunction.CountA(row) = 0 Then
        MsgBox "row " & i & " is empty"
    End If

Next i

언급URL : https://stackoverflow.com/questions/3628057/how-to-find-out-if-an-entire-row-is-blank-in-excel-thorough-vba