Excel 求助VBA编写自动生成表格
答案:2 悬赏:70 手机版
解决时间 2021-11-18 11:23
- 提问者网友:活着好累
- 2021-11-18 04:35
Excel 求助VBA编写自动生成表格
最佳答案
- 五星知识达人网友:千夜
- 2021-11-18 05:46
1、VBA是一个工具,你得会用它才能实现你的需求。
2、首先要提供表格的格式
3、以下是一段生成表格的代码,可以试一下。
Sub lqxs()
Dim Arr, ks, js, nm1$, nm2$, dz1$, dz2$
Dim dz$, dz3$, yy$, nm$
Application.ScreenUpdating = False
Sheet3.Activate
Arr = [a1].CurrentRegion
ks = 3: js = UBound(Arr) - 1
nm = Sheet3.Name
yy = Left(nm, Len(nm) - 3)
nm1 = "图表 6"
nm2 = "图表 4"
dz = "A2:B" & js & ",D2:E" & js
ActiveSheet.ChartObjects(nm1).Activate
With ActiveChart
.SetSourceData Source:=Sheets(nm).Range(dz), PlotBy:=xlColumns
.SeriesCollection(1).Select
dz1 = "R3C2:R" & js & "C2"
.SeriesCollection(1).Values = "='" & nm & "'!" & dz1
dz2 = "R3C4:R" & js & "C4"
.SeriesCollection(2).Values = "='" & nm & "'!" & dz2
dz3 = "R3C5:R" & js & "C5"
.SeriesCollection(3).Values = "='" & nm & "'!" & dz3
.ChartTitle.Select
Selection.Characters.Text = yy & "月份合格率"
End With
ActiveSheet.ChartObjects(nm2).Activate
With ActiveChart
.ChartArea.Select
dz = "H2:T2,H" & js + 1 & ":T" & js + 1
.SetSourceData Source:=Sheets(nm).Range(dz), PlotBy:= _
xlRows
dz2 = "R" & js + 1 & "C8:R" & js + 1 & "C20"
.SeriesCollection(1).Values = "='" & nm & "'!" & dz2
.ChartTitle.Select
Selection.Characters.Text = yy & "月份不良趋势统计"
End With
Range("A" & ks).Select
Application.ScreenUpdating = True
MsgBox "OK"
End Sub
2、首先要提供表格的格式
3、以下是一段生成表格的代码,可以试一下。
Sub lqxs()
Dim Arr, ks, js, nm1$, nm2$, dz1$, dz2$
Dim dz$, dz3$, yy$, nm$
Application.ScreenUpdating = False
Sheet3.Activate
Arr = [a1].CurrentRegion
ks = 3: js = UBound(Arr) - 1
nm = Sheet3.Name
yy = Left(nm, Len(nm) - 3)
nm1 = "图表 6"
nm2 = "图表 4"
dz = "A2:B" & js & ",D2:E" & js
ActiveSheet.ChartObjects(nm1).Activate
With ActiveChart
.SetSourceData Source:=Sheets(nm).Range(dz), PlotBy:=xlColumns
.SeriesCollection(1).Select
dz1 = "R3C2:R" & js & "C2"
.SeriesCollection(1).Values = "='" & nm & "'!" & dz1
dz2 = "R3C4:R" & js & "C4"
.SeriesCollection(2).Values = "='" & nm & "'!" & dz2
dz3 = "R3C5:R" & js & "C5"
.SeriesCollection(3).Values = "='" & nm & "'!" & dz3
.ChartTitle.Select
Selection.Characters.Text = yy & "月份合格率"
End With
ActiveSheet.ChartObjects(nm2).Activate
With ActiveChart
.ChartArea.Select
dz = "H2:T2,H" & js + 1 & ":T" & js + 1
.SetSourceData Source:=Sheets(nm).Range(dz), PlotBy:= _
xlRows
dz2 = "R" & js + 1 & "C8:R" & js + 1 & "C20"
.SeriesCollection(1).Values = "='" & nm & "'!" & dz2
.ChartTitle.Select
Selection.Characters.Text = yy & "月份不良趋势统计"
End With
Range("A" & ks).Select
Application.ScreenUpdating = True
MsgBox "OK"
End Sub
全部回答
- 1楼网友:英雄的欲望
- 2021-11-18 06:38
什么表格?发来看看,说说要求?
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯