범위내의 그림/사진의 숫자를

이 기능은 한 영역의 이미지 수를 확인하고 싶을 때 사용할 수 있습니다.

함수는 대상 영역에 이미지/뷰를 추가한다고 해서 함수의 결과를 즉시 반환하지 않습니다.

함수를 사용한 후 결과를 다시 사용하려면 사용한 셀을 다시 입력해야 합니다.

F9키로 재계산해도 렌더링이 안되고,

F2로 셀을 편집하거나 두 번 클릭하는 동안 Enter 또는 Tab으로 입력해야 합니다.

CountP(Range): 셀의 왼쪽 위 모서리가 범위에 있으면 숫자를 계산합니다.

CountPA(Range): 이미지가 범위 내에 있어도 숫자를 센다.


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