Board logo

標題: [發問] 苦惱... 菜鳥EXCEL VBA 求助 [打印本頁]

作者: sandy0107    時間: 2012-12-2 03:32     標題: 苦惱... 菜鳥EXCEL VBA 求助

應該是個簡單的程序但腦殘起來就是想不通...
已經試過好多不同方式但都不行所以想搵師兄師姐求救 ><><><

以下是小妹PLOT GRAPH 時用的CODE...
Dim SMA_day As Integer
Dim stockno As String
Dim row As String

stockno = CStr(ThisWorkbook.Sheets("control").Cells(6, "K").Value)
SMA_day = CInt(ThisWorkbook.Sheets("control").Cells(5, "K").Value)
row = SMA_day + 1

ThisWorkbook.Sheets(stockno).Shapes.AddChart.Select
ThisWorkbook.Sheets(stockno).Shapes.AddChart.Chart.ChartType = xlLine
ThisWorkbook.Sheets(stockno).Shapes.AddChart.Chart.SetSourceData Source:=Range(stockno & "$A$2A" & row, stockno & "$H$2H$" & row)

到SET RANGE時總會有BUG... 但又改不回來
會不會是 ! 的位置錯了尼...? 應該怎樣解決?? 求救 >< ><
作者: kimbal    時間: 2012-12-2 09:49

回復 1# sandy0107

試試這樣?
  1. Dim SMA_day As Integer
  2. Dim stockno As String
  3. Dim row As string

  4. stockno = CStr(ThisWorkbook.Sheets("control").Cells(6, "K").Value)
  5. SMA_day = CInt(ThisWorkbook.Sheets("control").Cells(5, "K").Value)
  6. row = trim(str(SMA_day + 1))

  7. ThisWorkbook.Sheets(stockno).Shapes.AddChart.Select
  8. ThisWorkbook.Sheets(stockno).Shapes.AddChart.Chart.ChartType = xlLine
  9. ThisWorkbook.Sheets(stockno).Shapes.AddChart.Chart.SetSourceData Source:=Range(stockno & "$A$2:$A$" & row, stockno & "$H$2:$H$" & row)
  10.    
複製代碼

作者: 198188    時間: 2012-12-2 09:55

回復 2# kimbal

高人請問可否幫我解決我下面link的問題?謝謝~
    http://forum.twbts.com/thread-8403-1-1.html
作者: stillfish00    時間: 2012-12-2 10:59

本帖最後由 stillfish00 於 2012-12-2 11:00 編輯

回復 1# sandy0107
你的這段程式放在哪?
如果放在模組或其他工作表內
ThisWorkbook.Sheets(stockno).Shapes.AddChart.Chart.SetSourceData Source:=Range(stockno & "$A$2A" & row, stockno & "$H$2H$" & row)
Range前面記得指定哪個sheet

或者附上檔案看看
作者: sandy0107    時間: 2012-12-2 14:13

回復 2# kimbal

回復了也不行呢 >< ><
可能是偶表達不好... 把原檔貼上來請教大家 ><
http://dl.dropbox.com/u/84304423/ShareAnalyzer%201.xlsm
作者: sandy0107    時間: 2012-12-2 14:14

回復 4# stillfish00


看不太懂... @@
附上原檔在這裡
http://dl.dropbox.com/u/84304423/ShareAnalyzer%201.xlsm
感謝幫忙 ><
作者: stillfish00    時間: 2012-12-2 15:28

回復 6# sandy0107
改成這樣試試
Public Sub plot_SMA()
   
    Dim SMA_day As Integer
    Dim stockno As String
    Dim row As String
   
   
    stockno = CStr(ThisWorkbook.Sheets("control").Cells(6, "K").Value)
    SMA_day = CInt(ThisWorkbook.Sheets("control").Cells(5, "K").Value)
    row = SMA_day + 1


    With ThisWorkbook.Sheets(stockno).Shapes.AddChart
        .Chart.ChartType = xlLine
        .Chart.SetSourceData Source:=Range(stockno & "!$A$2:A" & row & ", " & stockno & "!$H$2:H$" & row)
    End With
   
    'activate stock sheet
    ThisWorkbook.Worksheets(stockno).Activate

End Sub
作者: sandy0107    時間: 2012-12-2 16:07

回復 7# stillfish00


出來了出來了 !!
謝謝喔 !!^3^




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)