office交流網--QQ交流群號

Access培訓群:792054000         Excel免費交流群群:686050929          Outlook交流群:221378704    

Word交流群:218156588             PPT交流群:324131555

Excel如何在單元格內顯示圖錶(摺線圖)

2017-07-11 17:51:00
zstmtony
原創
7568

Excel的圖錶是非常強大的,但很少有人在單元格內放置圖錶,而且圖錶對象也是比較重。但不用圖錶對象,能否實現摺線圖呢

就有這些Excel強人,硬生生地給實現瞭。

看看他們是如何做到的


作者:Excel小子


blob.png

操作動畵:

Excel小子2QQ圖片20161109212345.gif


實現代碼:

Sub 宏3()

'

' 宏3 宏

'


'

Dim sh As Shape, t, q

Dim rg As Range, r As Range, rr As Range, i

For Each sh In ActiveSheet.Shapes

    sh.Delete

Next sh


For t = 1 To Range("a1").CurrentRegion.Columns.Count

    For q = 1 To Range("a1").CurrentRegion.Rows.Count

    Set rg = Cells(q, t)

If Len(rg.Value) > 0 Then


i = i + 1

If i = 1 Then

    Set r = rg

Else

    

      ActiveSheet.Shapes.AddConnector(msoConnectorStraight, r.Left + r.Width / 2, r.Top + r.Height / 2, rg.Left + rg.Width / 2, _

        rg.Top + rg.Height / 2).Select

        With Selection.ShapeRange.Line

        .Visible = msoTrue

        .ForeColor.RGB = RGB(255, 0, 0)

        .Transparency = 0

    End With

    With Selection.ShapeRange.Line

        .Visible = msoTrue

        .Weight = 2.25

    End With

    

        Set r = rg

        End If

     End If

Next q

Next t


End Sub


作者:江蘇大俠

blob.png


演示動畵:

江蘇大俠QQ圖片20161109211721.gif


實現 代碼:

Function s(rng As Range)

    On Error Resume Next

    Set ce = rng(rng.Count).Offset(0, 1)

    For Each Shp In ce.Worksheet.Shapes

        ce.Worksheet.Shapes(ce.Address(, , xlR1C1) & "shape").Delete

    Next

    c = rng.Count

    w = ce.Width - 0.2

    h = ce.Height - 0.2

    ma = Application.Max(rng)

    With ce.Worksheet.Shapes

        x1 = ce.Left

        y1 = ce.Top + ce.Height - rng(1) / ma * h

        For i = 2 To c

            x2 = x1 + w / (c - 1)

            y2 = ce.Top + ce.Height - rng(i) / ma * h

            Set Shp = .AddLine(x1, y1, x2, y2)

            Shp.Name = ce.Address(, , xlR1C1) & "shape"

            x1 = x2

            y1 = y2

        Next

    End With

    s = ""

End Function


分享