VB realizes automatic generation of statistical charts

Click the link to join the QQ group 522720170 (free public classes, videos are available): https://jq.qq.com/?_wv=1027&k=5C08ATe

 

The solution mainly solves how to complete the realization through the button at one time

The table automatically generates statistical charts.

user target audience

People who need to count various histograms, pie charts, and trend charts.

Functional Overview

1. Automatically select tables and automatically generate statistical charts.

2. Automatically set the chart style and format

3. Set the button to meet the 'one-click completion of statistical charts'

Main function interface

VB realizes automatic generation of statistical charts

figure 1

VB realizes automatic generation of statistical charts

figure 2

Solution advantage

Advantage 1: The function of TD REQUIREMENT is extended to provide specific requirements-use case coverage values ​​(coverage ratio).

Advantage 2: It is convenient for requirements management, and real-time assessment of whether test cases meet the standard "100% coverage of product requirements".

Advantage 3: Add fields, in line with the characteristics of the project requirements list.

Scheme configuration

1. Original form

Take 'History_bug.xls' regularly exported from TD database as an example

VB realizes automatic generation of statistical charts

Table 2

2. Call VB in EXCEL to realize the function of filtering Reopen records

Effect picture:

VB realizes automatic generation of statistical charts

table 3

Attachment: VB encoding

Sub MacroName()

'

' MacroName Macro

'

' Shortcut: Ctrl+a

'

Columns("G:G").Select

ActiveCell.FormulaR1C1 = "=VLOOKUP(""Reopen"",History_bug!$A$2:$G$2000,7,False)"

//Add filter formula

End Sub

3 By one-click 'button 1', the report chart is automatically generated.

E.g

VB realizes automatic generation of statistical charts

Table 4

Effect picture:

VB realizes automatic generation of statistical charts

image 3

Attachment: VB source code

Sub MacroName()

'

' MacroName Macro

' Require content and ratios to be displayed in the pie chart

'

' Shortcut: Ctrl+a

'

Range("A1:A13,B1:B13").Select //Define list range

Range("B1").Activate //Call Excel to insert chart function

ActiveSheet.Shapes.AddChart.Select

ActiveChart.SetSourceData Source: = Range (_

"'Sheet1'!$A$1:$A$13,'Sheet1'!$B$1:$B$13")

ActiveChart.ChartType = xlPie //Call the pie chart function in the chart

ActiveChart.ApplyLayout (1) //Pie Chart Design

ActiveChart.ChartStyle = 26 //pie chart format

ActiveChart.ClearToMatchStyle

End Sub

4. If you consider the total amount of consideration data, there are both total/sub-item values ​​and percentages, which can be represented by a bar graph.

Attachment: VB source code

Sub Macro Name()

'

' MacroName Macro

' bar ratio with no data labels set

'

' Shortcut: Ctrl+a

'

Range("A1:C8").Select //Define list range

ActiveSheet.Shapes.AddChart.Select //Select to insert the chart

ActiveChart.SetSourceData Source:=Range("'Sheet1'!$A$1:$C$8")

ActiveChart.ChartType = xlBarStacked100 //Call the bar chart in the chart

ActiveChart.ApplyLayout (1)

ActiveChart.Axes(xlValue).Select //Open the horizontal x-axis edit box

ActiveChart.Axes(xlValue).MajorUnit = 0.1

ActiveChart.Axes(xlValue).MajorUnit = 0.02 //Define the scale of the horizontal axis

ActiveSheet.ChartObjects("图表 1").Activate

Application.Left = 82.75 //The left and right length of the chart

Application.Top = 15 //Chart top and bottom width

End Sub

5. If desired, the bar graphs show content and ratio separately (ie, with set data labels).

E.g:

VB realizes automatic generation of statistical charts

table 5

Effect picture:

VB realizes automatic generation of statistical charts

Figure 4

Attachment: VB source code

Sub Macro Name()

'

' MacroName Macro

'Require content and ratios to be displayed in a bar chart

'

' Shortcut: Ctrl+a

'

Range("A1:C8").Select //Define the table range such as the picture above

ActiveSheet.Shapes.AddChart.Select //Select to insert the chart

ActiveChart.SetSourceData Source:=Range("'Sheet1'!$A$1:$C$8")//

ActiveChart.ChartType = xlBarStacked100 //Call the bar chart in the chart

ActiveChart.ApplyLayout (1) //Select the format

ActiveChart.ChartStyle = 26 //Select style

ActiveChart.ClearToMatchStyle

ActiveChart.Axes(xlValue).Select //Open the X-axis edit box

ActiveChart.Axes(xlValue).MajorUnit = 0.2 //X-axis default coordinate value

ActiveChart.Axes(xlValue).MajorUnit = 0.02 //Define the X-axis coordinate value

ActiveSheet.ChartObjects("Chart 1").Activate //Select the generated chart

ActiveChart.SeriesCollection(1).Select

ActiveChart.SeriesCollection(1).ApplyDataLabels //Open to set the data label format

ActiveChart.SeriesCollection(2).Select

ActiveChart.SeriesCollection(2).ApplyDataLabels //Open to set the data label format

ActiveWindow.ScrollColumn = 2

ActiveWindow.ScrollColumn = 1

ActiveSheet.ChartObjects("Chart 1").Activate //Select the generated chart

Application.Left = 82.75 //The left and right length of the chart

Application.Top = 15 //Chart top and bottom width

End Sub

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325068539&siteId=291194637