vba 根据 excel 单元格的整数添加形状(星星)
vba add shapes (stars) in function of an excel cell's integer
我在电子表格中有一列“I”,它给出了从 1 到 5 的整数。根据 integer/ranking 超过 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" & 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
但是当我使用一个程序来刷新我的列 I 和整数时,我正在寻找一种方法来删除我之前创建的星星,然后应用新的 ranking/number 星星。
我在我的代码之前尝试过类似的东西:
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
你也可以在created.Something喜欢
时给星星命名
'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
地址,按此删除。
我在电子表格中有一列“I”,它给出了从 1 到 5 的整数。根据 integer/ranking 超过 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" & 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
但是当我使用一个程序来刷新我的列 I 和整数时,我正在寻找一种方法来删除我之前创建的星星,然后应用新的 ranking/number 星星。
我在我的代码之前尝试过类似的东西:
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
你也可以在created.Something喜欢
时给星星命名'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
地址,按此删除。