ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
楼主: 蓝桥玄霜

[分享] (蓝桥收藏)我的Excel VBA分类实例收藏

    [复制链接]

TA的精华主题

TA的得分主题

发表于 2020-9-28 22:25 | 显示全部楼层
本帖已被收录到知识树中,索引项:模板和开源系统
请教蓝老一个问题,方法add作用与对象chart object时失败怎么解决

TA的精华主题

TA的得分主题

发表于 2020-9-28 22:30 | 显示全部楼层
运行到Set mychart = ActiveSheet.ChartObjects.Add(.Cells(k, 9).Left, .Cells(k, 9).Top, 620, 280)
时出错,同一个文件有的电脑可以有的出错
Sub new_chart()
        Dim mychart As ChartObject, j As Integer, k As Integer, i As Integer, ws As Worksheet, d As Integer, z As Integer
        Dim actchart As ChartObject
        Sheets("Density").Activate
        d = Sheets("density").Range("C1:QN1").Find(what:=Date - 1).Column
        Set ws = Sheets("MAP & Chart")
        z = 0
        For k = 1 To 57 Step 7 '43gia55
        z = z - 1
        ws.Activate
        With ws
        For Each mychart In ws.ChartObjects
            If mychart.Name = .Cells(k, 9).Value Then mychart.Delete
        Next mychart
        Set mychart = ActiveSheet.ChartObjects.Add(.Cells(k, 9).Left, .Cells(k, 9).Top, 620, 280)
        mychart.Name = .Cells(k, 9)
            With mychart.Chart
                   .HasTitle = True
                   .ChartTitle.Text = mychart.Name & "_Defect_Density"
                   .ChartTitle.Font.Size = 18
                   .Axes(xlValue).MajorGridlines.Delete
                   .ChartGroups(1).GapWidth = 100
                   .HasLegend = True
                   .Legend.Font.Size = 16
                   .Legend.Position = xlLegendPositionRight
                    For i = 1 To 4
                          With .SeriesCollection.NewSeries
                                .Values = Range(Sheets("density").Cells(1 + i, d - 11), Sheets("density").Cells(1 + i, d))
                                .XValues = Range(Sheets("density").Cells(1, d - 11), Sheets("density").Cells(1, d))
                                .Name = Sheets("density").Cells(1 + i, 2)
                                .AxisGroup = 1
                                .ChartType = xlColumnStacked
                                Select Case i
                                    Case 1
                                        With .Format.Fill
                                        .Visible = msoTrue
                                        .ForeColor.RGB = RGB(5, 70, 255)
                                        '.ForeColor.RGB = RGB(190, 190, 190)
                                        .Transparency = 0.618
                                        .Solid
                                        End With
         
                                    Case 2
                                        With .Format.Fill
                                        .Visible = msoTrue
                                        .ForeColor.RGB = RGB(0, 210, 0)
                                        '.ForeColor.RGB = RGB(50, 50, 50)
                                        .Transparency = 0.618
                                        .Solid
                                        End With
                     
                                    Case 3
                                        With .Format.Fill
                                        .Visible = msoTrue
                                        .ForeColor.RGB = RGB(201, 137, 9)
                                        '.ForeColor.RGB = RGB(10, 10, 10)
                                        .Transparency = 0.618
                                        .Solid
                                        End With
                    
                                    Case 4
                                        With .Format.Fill
                                        .Visible = msoTrue
                                        .ForeColor.RGB = RGB(226, 30, 203)
                                       ' .ForeColor.RGB = RGB(150, 150, 150)
                                        .Transparency = 0.8
                                        .Solid
                                        End With
                                End Select
                          End With
                    Next i
                    For j = 1 To 6
                         With .SeriesCollection.NewSeries
                             .Values = Range(Sheets("density").Cells(5 + j + k + z, d - 11), Sheets("density").Cells(5 + j + k + z, d))
                             .XValues = Range(Sheets("density").Cells(1, d - 11), Sheets("density").Cells(1, d))
                             .Name = Sheets("density").Cells(5 + j + k + z, 2)
                             .ChartType = xlLineMarkers
                             .MarkerSize = 5
                             .AxisGroup = 2
                              
                             Select Case j
                                    Case 1
                                        .MarkerStyle = xlMarkerStyleDiamond
                                        .MarkerSize = 5
                                        With .Format.Line
                                        .Visible = msoTrue
                                        .ForeColor.RGB = RGB(5, 70, 255)
                                        .Weight = 2.5
                                    
                                        End With
                                    Case 2
                                        .MarkerStyle = xlMarkerStyleDiamond
                                        .MarkerSize = 5
                                        With .Format.Line
                                        .Visible = msoTrue
                                        .ForeColor.RGB = RGB(0, 210, 0)
                                        .Weight = 2.5
                                      
                                        End With
                                    Case 3
                                        .MarkerStyle = xlMarkerStyleDiamond
                                        .MarkerSize = 5
                                        With .Format.Line
                                        .Visible = msoTrue
                                        .ForeColor.RGB = RGB(201, 137, 9)
                                        .Weight = 2.5
                                    
                                        End With
                                    Case 4
                                        .MarkerStyle = xlMarkerStyleDiamond
                                        .MarkerSize = 5
                                        With .Format.Line
                                        .Visible = msoTrue
                                        .ForeColor.RGB = RGB(226, 30, 203)
                                        .Weight = 2.5
                                      
                                        End With
                                    Case 5
                                        .MarkerStyle = -4142
                                        With .Format.Line
                                        .Visible = msoTrue
                                        .ForeColor.RGB = RGB(255, 62, 58)
                                        .DashStyle = msoLineLongDash
                                        .Weight = 2.5
                                        End With
                                      Case 6
                                        .MarkerStyle = -4142
                                        With .Format.Line
                                        .Visible = msoTrue
                                        .ForeColor.RGB = RGB(255, 62, 58)
                                        .Weight = 2.5
                                        End With
                                End Select
                                With mychart.Chart.Axes(xlValue, xlPrimary)
                                 .TickLabels.Font.Size = 16
'                                .HasTitle = True
'                                .AxisTitle.Text = "Move"
'                                .AxisTitle.Orientation = xlVentical
'                                .AxisTitle.Font.Size = 16
                                End With
                                 With mychart.Chart.Axes(xlValue, xlSecondary)
                                    .TickLabels.Font.Size = 16
                                End With
                                 With mychart.Chart.Axes(xlCategory)
                                    .TickLabels.Font.Size = 16
                                End With
                                With mychart.Chart
                                    .HasLegend = True
                                    .Legend.Font.Size = 11
                                    .Legend.Position = xlLegendPositionTop
                                End With
                        End With
                    Next j
            End With
            
       End With
       Next k
End Sub

TA的精华主题

TA的得分主题

发表于 2020-9-29 14:51 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
谢谢分享!!

TA的精华主题

TA的得分主题

发表于 2020-9-30 10:30 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2020-9-30 11:13 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2020-10-5 22:47 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2020-10-5 23:22 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2020-10-6 08:44 | 显示全部楼层
十分感谢,有了这些就可以太高效率了。

TA的精华主题

TA的得分主题

发表于 2020-10-6 09:11 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
新人像高手学习

TA的精华主题

TA的得分主题

发表于 2020-10-7 16:01 | 显示全部楼层
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-5-12 16:31 , Processed in 0.047864 second(s), 6 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表