首页 > WPS教程 >

excel怎么识别带图片的单元格

WPS教程 2023-05-29 22:27:41

excel怎么识别带图片单元格

Q前不久有网友问我,在工作表的一列中,有些单元格放置有图片,有些单元格为空,如何识别带有图片单元格并输入相应的文字?如所示,对工作表Sheet1的列B中含有图片单元格,输入“有图片”,而没有图片单元格则输入“无图片”,效果如列G所示

A:下面的代码可以完成我们的需求:

Sub DecidePic()

Dim cell As Range

Dim lngCells As Long

Application.ScreenUpdating = False

设置查找列的单元格

lngCells = 3

For Each cell In Range(“B2:B”& lngCells)

if PicifExists(Sheet1, cell) Then

cell.Value = “有图片

Else

cell.Value = “无图片

End if

Next cell

Application.ScreenUpdating = True

End Sub

Function PicifExists(wks As Worksheet, rng As Range) As Boolean

Dim shp As Shape

For Each shp In wks.Shapes

if shp.TopLeftCell.Address =rng.Address Then

PicifExists = True

Exit For

End if

Next shp

End Function

自定义函数PicifExists中,使用Shape对象的TopLeftCell属性来获取图片所在单元格的地址,然后与单元格相比较,以判断单元格中是否含有图片


标签: WPS excel ppt图片修改透明度 ppt图片怎么修改透明度 ppt图片透明度 图片 ppt背景图片 ppt背景图片设置 单元 识别 如何设置WPS图案图

Copyright © 2016-2023 书吧网-Office教程网 . Some Rights Reserved. 备案号:苏ICP备16060189号