VB操作Excel动态单元格选择问题
VB操作Excel绘制图表,当N=5时,图表横坐标为5个值,当N=i时,图表横坐标为i个值,横坐标单元格选择怎么写Char.FullSeriesCollection(i).XValues = "sheet(1)!$B$6:$F$6",请各位前辈指教!
程序代码:
Dim EXAPP As Excel.Application Dim WB As Excel.Workbook Dim sht As Excel.Worksheet Dim chartPage As Excel.Chart Dim xlCharts As Excel.ChartObjects Dim myChart As Excel.ChartObject Dim chartRange As Excel.Range Private Sub Command1_Click() Set xlCharts = sht.ChartObjects Set myChart = xlCharts.Add(10, 80, 300, 250) Set chartPage = myChart.Chart Set chartRange = sht.Range("a1", "d5") Call chartPage.SetSourceData(Source:=chartRange) chartPage.ChartType = Excel.XlChartType.xlColumnClustered End Sub Private Sub Form_Load() Set EXAPP = CreateObject("excel.application") EXAPP.Visible = True Set WB = EXAPP.Workbooks.Open("c:\chart.xlsx") Set sht = WB.Worksheets("sheet1") End Sub Private Sub Form_Unload(Cancel As Integer) WB.Close Set myChart = Nothing Set xlCharts = Nothing Set sht = Nothing Set WB = Nothing Set EXAPP = Nothing End Sub