[算表] 請益-使用VBA定義圖表橫軸

看板Office作者 (無事草包)時間13年前 (2013/04/04 10:46), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
軟體: Excel 版本:2007 先附上我的 code : ----------------------------------------------- Sub test() ' get x-lable ActiveSheet.Cells(2, 2).Select xAxis_s = ActiveCell.Address xAxis_e = ActiveCell.End(xlDown).Address ' get import ActiveSheet.Cells(2, 3).Select import_s = ActiveCell.Address import_e = ActiveCell.End(xlDown).Address ' get export ActiveSheet.Cells(2, 4).Select export_s = ActiveCell.Address export_e = ActiveCell.End(xlDown).Address '---------------------------------- Charts.Add ActiveSheet.Shapes.AddChart.Select ' ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range(import_s, import_e) ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1" ActiveChart.ChartType = xlXYScatterLines '------------------------------- 'ActiveChart.SeriesCollection(1).XValues = Sheets("Sheet1").Range(xAxis_s, xAxis_e) ActiveChart.SeriesCollection(1).Values = Sheets("Sheet1").Range(import_s, import_e) ActiveChart.SeriesCollection(1).Name = "=""import""" '--------------------------------- ActiveChart.SeriesCollection.NewSeries ActiveChart.SeriesCollection(2).XValues = Sheets("Sheet1").Range(xAxis_s, xAxis_e) ActiveChart.SeriesCollection(2).Values = Sheets("Sheet1").Range(export_s, export_e) ActiveChart.SeriesCollection(2).Name = "=""export""" '--------------------------------- '這段是layout設定 省略 End Sub ------------------------------------------ 小弟這幾天初探VBA 查了手邊的書和google大神後 Ver 拼湊出以上的code a.1 a.5 我的問題是 b.3 圖表畫出來之後 b.5 其橫軸不是我所設定的 xAxis c.7 我的xAxis資料欄位如右方所表示的那樣 d.1 出現的反而是單純的數字 嘗試了以下兩種方式都無法解決 1. 將xlXYScatterLines 改為 xlLineMarkers 其餘不變 雖然橫軸正確了 但跳出以下錯誤訊息 "執行階段錯誤424 此處需要物件" 只有這段文字 在何處錯誤或需要物件則是毫無頭緒 2. google也找不到相關案例 以上是我的問題 懇求各位先進 提點一下 感謝!! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.37.169.58
文章代碼(AID): #1HNEbkeY (Office)
文章代碼(AID): #1HNEbkeY (Office)