Excel - VBA

범위내의 그림/사진의 숫자를 가져오기

EGTools 2023. 2. 18. 11:16
728x90

범위내에 그림의 수를 확인하고 싶을 때 사용할 수 있는 함수입니다.

 

함수는 대상 영역에 그림/시진을 추가한다고 함수 결과가 즉시 반영되지 않습니다.

함수를 사용한 후에 그 결과를 다시 사용할 경우에는 반드시 사용셀을 재입력하세요.

F9키로 재계산으로 해도 반영되지 않으며,

반드시 F2 키나  더블클릭으로 셀 수정 상태에서 Enter나 Tab키로 입력합니다.

 

CountP( 범위 ) : 셀의 왼쪽위 꼭지점이 범위에 있으면 숫자를 셈

CountPA( 범위 ) : 그림이 범위내에 걸치기만 해도 숫자를 셈

 

 

Option Explicit

Public Function CountP(aRange As Range)
    Dim oPic As Shape, iCnt As Long
    For Each oPic In aRange.Parent.Shapes
        If oPic.Type = msoPicture Or oPic.Type = msoLinkedPicture Then
        If Not Intersect(oPic.TopLeftCell, aRange) Is Nothing Then
            iCnt = iCnt + 1
        End If
        End If
    Next oPic
    CountP = iCnt
End Function

Public Function CountPA(aRange As Range)
    Dim oPic As Shape, iCnt As Long
    For Each oPic In aRange.Parent.Shapes
        If oPic.Type = msoPicture Or oPic.Type = msoLinkedPicture Then
        If Not Intersect(Range(oPic.TopLeftCell.Address, oPic.BottomRightCell.Address), aRange) Is Nothing Then
            iCnt = iCnt + 1
        End If
        End If
    Next oPic
    CountPA = iCnt
End Function

 

728x90