VBA 作XY散点图,修改并复制线性方程式

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Sub Plot2_logYYf()‘中图

Range("B13:B95,H13:I95").Select

ActiveSheet.Shapes.AddChart.Select

With ActiveChart‘设定表格格式

.ChartType = xlXYScatter

.ApplyLayout (1)

.ChartTitle.Text = ""

.SetSourceData Source:=Range( _

"$B$13:$B$95,$H$13:$I$95")

.Axes(xlCategory).TickLabels.NumberFormat = "#,##0"

.Axes(xlValue).TickLabels.NumberFormat = "#0.0"

.Axes(xlValue).HasMajorGridlines = False

.Axes(xlValue).MaximumScale = 0

.Axes(xlValue).MinimumScale = -4

.HasLegend = False

.SeriesCollection(1).MarkerSize = 3

.SeriesCollection(1).MarkerStyle = 2

.SeriesCollection(2).MarkerSize = 3

.SeriesCollection(2).MarkerStyle = 8

End With

ActiveChart.SeriesCollection(1).Trendlines.Add‘作1线性方程

ActiveChart.SeriesCollection(1).Trendlines(1).Select

Selection.DisplayEquation = True

ActiveChart.SeriesCollection(1).Trendlines(1).DataLabel.Select

Selection.Format.TextFrame2.TextRange.Font.Size = 18‘修改方程式文体大小,也可以设定颜色

ActiveChart.SeriesCollection(1).Trendlines(1).Select

Selection.DisplayEquation = False‘这一步很必要,不然修改的方程式不能自动更新

Selection.DisplayEquation = True

ActiveChart.SeriesCollection(2).Trendlines.Add‘作2线性方程

ActiveChart.SeriesCollection(2).Trendlines(1).Select

Selection.DisplayEquation = True

ActiveChart.SeriesCollection(2).Trendlines(1).DataLabel.Select

Selection.Format.TextFrame2.TextRange.Font.Size = 18‘修改方程式文体大小

Selection.Format.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(255, 0, 0)‘设定方程式文体颜色

ActiveChart.SeriesCollection(2).Trendlines(1).Select

Selection.DisplayEquation = False

Selection.DisplayEquation = True

'Range("K5").Value = ActiveChart.SeriesCollection(2).Trendlines(1).DataLabel.Characters.Text‘将方程式文体赋值给"K5"

ActiveChart.ChartArea.Select

ActiveChart.Axes(xlPrimary).AxisTitle.Select

ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Text = "log(f )"‘横轴

Selection.Format.TextFrame2.TextRange.Characters.Text = "log(f )"

Selection.Format.TextFrame2.TextRange.Font.Size = 20

Selection.Format.TextFrame2.TextRange.Characters(5, 1).Font.Italic = msoTrue‘斜体

ActiveChart.ChartArea.Select

ActiveChart.Axes(xlValue).AxisTitle.Select

Selection.Format.TextFrame2.TextRange.Characters.Text = "log(Y1),log(Y2)"

Selection.Format.TextFrame2.TextRange.Font.Size = 20

With Selection.Format.TextFrame2.TextRange.Characters(1, 8).Font.Fill

.ForeColor.ObjectThemeColor = msoThemeColorText1

'.ForeColor.ObjectThemeColor = msoThemeColorText2 Bluecolor

'.ForeColor.Brightness = 0.400000006

End With

Selection.Format.TextFrame2.TextRange.Characters(5, 1).Font.Italic = msoTrue

Selection.Format.TextFrame2.TextRange.Characters(13, 1).Font.Italic = msoTrue

Selection.Format.TextFrame2.TextRange.Characters(14, 1).Font.BaselineOffset = - _0.25‘下标 Selection.Format.TextFrame2.TextRange.Characters(6, 1).Font.BaselineOffset = - _

0.25

With Selection.Format.TextFrame2.TextRange.Characters(9, 7).Font.Fill

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

End With

相关文档
最新文档