vba在excel单元格中添加形状(星形)';s整数
我在电子表格上有一列“I”,给出了1到5的整数。在整数/排名超过5的功能中,我设法在整数旁边的单元格中显示星星:vba在excel单元格中添加形状(星形)';s整数,vba,integer,ms-office,shapes,Vba,Integer,Ms Office,Shapes,我在电子表格上有一列“I”,给出了1到5的整数。在整数/排名超过5的功能中,我设法在整数旁边的单元格中显示星星: Dim x As Integer, Cel As Range, Plg As Range Dim y As Integer, etoile As Shape Dim shp As Shape With mysheet Set Plg = .Range("I" & startLine & ":I" & nbLin
Dim x As Integer, Cel As Range, Plg As Range
Dim y As Integer, etoile As Shape
Dim shp As Shape
With mysheet
Set Plg = .Range("I" & startLine & ":I" & nbLines)
For Each Cel In Plg
y = 5
For x = 1 To Cel.Value
If Cel > 0 Then
Set stars= .Shapes.AddShape(msoShape5pointStar, Cel.Left + y, Cel.Top + 5, 6, 6)
y = y + 10
stars.Line.Visible = msoFalse
stars.Fill.ForeColor.SchemeColor = 13
End If
Next x
Next Cel
End With
但是,当我使用一个程序刷新我的列和整数时,我正在寻找一种方法来删除我之前创建的星星,然后应用新的排名/星星数
在编写代码之前,我尝试过类似的东西:
For Each shp In mysheet.Shapes
If shp.Type = msoShapeTypeMixed Then shp.Delete
Next shp
没有巨大的成功。。。
任何帮助都将不胜感激 请尝试以下方法:
Dim sh As Worksheet, st As Shape
Set sh = ActiveSheet
For Each st In sh.Shapes
If st.Type = 1 And left(st.Name, 7) = "5-Point" Then st.Delete
Next
你也可以在创建时命名星星
'your existing code
'
Set stars= .Shapes.AddShape(msoShape5pointStar, Cel.Left + y, Cel.Top + 5, 6, 6)
y = y + 10
stars.Name = "MyStar" & "somethin else" '(maybe the Cel.Addres and use it in a similar way to delete only specific ones)
'your existing code
然后删除前6个字符的形状,如“MyStar”,或任何你喜欢的形状
如果您需要有选择地删除它们,您还可以确定它们的
TopLeftCell
地址,并根据此地址进行删除。是的,您找到了,先生!谢谢,第一个成功了perfectly@Pierre_CM:很高兴我能帮忙!但最好也探讨一下其余的建议。只是为了更好地理解和学习VBA…:)我实际上调试了第一个,并检查了对象的所有属性(名称+地址)。因此,它实际上帮助我获得了我错过的要点,而你提出了两种解决方案!