ExcelTip.Net留存知识帖 ---【注:附件之前被网盘供应商清空后,现已修复-现已修复-现已修复为本地下载!】
现在位置:首页 > E问E答 > Excel VBA > 如何批量生成雷达图

如何批量生成雷达图

作者:绿色风 分类: 时间:2022-08-17 浏览:266
楼主
hustclm
Q:如何用VBA批量生成雷达图?
A:用VBA代码批量生成。代码如下。
  1. Sub shengcheng()
  2.     Dim i As Integer
  3.     Dim j As Integer
  4.     Dim k As Integer, h As Integer
  5.     Dim sh1 As Worksheet, sh2 As Worksheet, mychart As ChartObject
  6.     Dim arr, arr1(1 To 10000)
  7.     Dim rng As Range, rng1 As Range
  8.     Application.ScreenUpdating = False
  9.     Set sh1 = Sheets("数据")
  10.     Set sh2 = Sheets("图表")
  11.     arr = sh1.Range("b2:b" & sh1.[b65536].End(xlUp).Row)
  12.     h = UBound(arr) / 2

  13.     r0 = 28
  14.     h1 = 8.5
  15.     w1 = 10

  16.     Set rng1 = sh1.Range("e1:o1")
  17.     For m = 2 To Cells(Rows.Count, 2).End(xlUp).Row
  18.         If Cells(m, 2).Value <> "" Then n = n + 1: arr1(n) = Cells(m, 2).Value
  19.     Next

  20.     If sh2.ChartObjects.Count > 0 Then
  21.         sh2.ChartObjects.Delete
  22.     End If

  23.     For i = 1 To h
  24.         j = 2 * i
  25.         k = 2 * i + 1
  26.         sh1.Activate
  27.         Set rng = sh1.Range(Cells(j, 4), Cells(k, 15))
  28.         sh2.Activate
  29.         ActiveSheet.Shapes.AddChart.Select
  30.         ActiveChart.ChartType = xlRadar
  31.         ActiveChart.SetSourceData Source:=rng
  32.         ActiveChart.SeriesCollection(1).XValues = rng1
  33.         Set mychart = ActiveSheet.ChartObjects(i)
  34.         With mychart
  35.             .Left = 10 + ((i - 1) Mod 3) * 300
  36.             .Top = (Int(i / 3.5) * (h1 * r0 + 5)) + 30
  37.             .Width = w1 * r0
  38.             .Height = h1 * r0
  39.             With mychart.Chart
  40.                 .HasTitle = True
  41.                 .ChartTitle.Text = arr1(i)
  42.             End With
  43.         End With
  44.     Next
  45.     Set rng = Nothing
  46.     Set rng1 = Nothing
  47.     Set arr = Nothing
  48.     Application.ScreenUpdating = True
  49.     sh2.Range("a1").Activate
  50. End Sub
效果图如下:
 




批量生成雷达图.rar
2楼
芐雨
3楼
亡者天下
4楼
海洋之星
不错,谢谢分享,学习了
5楼
hustclm
谢谢昆版的提醒,已添加效果图
6楼
kylecs
果断学些了
7楼
寒月悲茄
8楼
老糊涂
下载学习

免责声明

有感于原ExcelTip.Net留存知识的价值及部分知识具有的时间限定性因素, 经与ExcelTip.Net站长Apolloh商议并征得其同意, 现将原属ExcelTip.Net的知识帖采集资料于本站点进行展示, 供有需要的人士查询使用,也慰缅曾经的论坛时代。 所示各个帖子的原作者如对版权有异议, 可与本人沟通提出,或于本站点留言,我们会尽快处理。 在此,感谢ExcelTip.Net站长Apolloh的支持,感谢本站点所有人**绿色风(QQ:79664738)**的支持与奉献,特此鸣谢!
------本人网名**KevinChengCW(QQ:1210618015)**原ExcelTip.Net总版主之一

评论列表
sitemap