VBA在EXCEL中创建图形线条

EXCEL使用了多少行: ActiveSheet.UsedRange.Rows.Count(再也不用循环到头啦)

创建线条并命名:ActiveSheet.Shapes.AddLine(x1,y1,x2,y2).name="Line"&CSTR(i)

E.G.

Private Sub ClearPreviousLines()
    Const LINE_FLAG As String = "#LINE#"
      
    Dim myLine As Shape
      
    For Each myLine In ActiveSheet.Shapes
        If InStr(1, myLine.Name, LINE_FLAG, vbTextCompare) > 0 Then
            myLine.Delete
        End If
    Next
      
End Sub

    
Private Sub MarkCurrentProgress()
      
    Const LINE_FLAG As String = "#LINE#"
    Const RNG_MAIN_PROG As String = "B5"
    Const COL_PROGRESS As Integer = 10
    Const COLS_PROGRESS As Integer = 10
  
    Dim r As Long
    Dim x As Integer, y As Integer, h As Integer
      
      
    'Mark each step progress
    For r = 1 To ActiveSheet.UsedRange.Rows.Count
        strPercent = CStr(Cells(r, COL_PROGRESS).Value)
        If strPercent <> "" Then
            If IsNumeric(strPercent) Then
   
                With Cells(r, COL_PROGRESS)
                    x = .Left + (Cells(r, COL_PROGRESS + COLS_PROGRESS).Left - .Left) * .Value
                    y = .Top
                    h = .Height
                End With
                          
                ActiveSheet.Shapes.AddLine(x, y, x, y + h).Name = LINE_FLAG & CStr(r)
                          
            End If
        End If
    Next r
      
    'Mark main progress
    Range(RNG_MAIN_PROG).Select
    With Selection
        x = .Left + .Width * Selection(1, 1).Value
        y = .Top
        h = .Height
    End With
    ActiveSheet.Shapes.AddLine(x, y, x, y + h).Name = LINE_FLAG & "Main"
  
End Sub

 

转载于:https://www.cnblogs.com/jiceberg420/p/4671037.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值