返回列表 上一主題 發帖

[分享] 大盤每月每天歷史成交量與金額下載

回復 30# GBKEE

已正常執行
真的非常感謝GBKEE大大的熱心幫忙,謝謝您
stock

TOP

回復 30# GBKEE


GBKEE大大,我剛剛執行程式,發現小計算出的數值都不正確,請問要修改哪裡?不好意思再麻煩您幫忙,謝謝您
  1. Option Explicit
  2. Private Sub 更新()
  3.     With ActiveSheet
  4.         .Cells.Clear
  5.         With .QueryTables.Add("URL;http://www.taifex.com.tw/chinese/3/3_2_2.asp", ActiveSheet.[A1])
  6.             .WebFormatting = xlWebFormattingNone
  7.             .Refresh BackgroundQuery:=False
  8.             ActiveSheet.Names(.Name).Delete
  9.         End With
  10.         .Range("E:G,I:L,N:Q").Delete                                    '刪除多餘的欄
  11.         .Range("1:6,8:8").Delete                                        '刪除多餘的列
  12.         .Range("B1").End(xlDown).Offset(1).Resize(2).EntireRow.Delete   '刪除多餘的列
  13.         .Range("A:A").Insert                                            '插入一欄
  14.         .[B1].Resize(, 12) = Array("契約", "月份", "履約價", "買賣權", "成交價", "未平倉量", "CALL", "=C2", "call-oi", "put-oi", "call-oi$", "put-oi$")
  15.         '**  "=C2" 可修改為 正確的參照  ***
  16.         With .Range("b2", .[b2].End(xlDown))
  17.             .Offset(, -1) = "=rc4 +rc8 + rc9"
  18.             .Columns(5).Replace "-", ""
  19.             .Columns(7) = "=IF(rc[-3]=""Call"",1,0)"    'R1C1表示法 : 工作表上腧入公式
  20.             .Columns(8) = "=IF(rc[-6]=r1c9,1,8)"
  21.             .Columns(9) = "=IF(rc[-2]=1,rc[-3],0)"
  22.             .Columns(10) = "=IF(rc[-3]=0,rc[-4],0)"
  23.             .Columns(11) = "=if(rc[-1]=0,rc[-6]*rc[-5],"""")"
  24.             .Columns(12) = "=if(rc[-2]<>0,rc[-7]*rc[-6],"""")"
  25.         End With
  26.         .UsedRange.Value = .UsedRange.Value             '消除公式
  27.         .Columns.AutoFit
  28.         With .Range("b2", .[b2].End(xlDown))
  29.             .Offset(, -1) = "=rc4 +rc8 + rc9"
  30.             .Columns(5).Replace "-", ""
  31.             .Columns(7) = "=IF(rc[-3]=""Call"",1,0)"    'R1C1表示法 : 工作表上腧入公式
  32.             .Columns(8) = "=IF(rc[-6]=r1c9,1,8)"
  33.             .Columns(9) = "=IF(rc[-2]=1,rc[-3],0)"
  34.             .Columns(10) = "=IF(rc[-3]=0,rc[-4],0)"
  35.             .Columns(11) = "=if(rc[-1]=0,rc[-6]*rc[-5],"""")"
  36.             .Columns(12) = "=if(rc[-2]<>0,rc[-7]*rc[-6],"""")"
  37.              With .Cells(.Rows.Count + 1, 1) '.Rows.Count + 1 範圍內資料總列數+1
  38.                 .Cells(1, 0) = "小計"
  39.                 .Cells(1, 6) = Application.Sum(.Parent.Columns(6))
  40.                 .Cells(1, 9) = Application.Sum(.Parent.Columns(9))
  41.                 .Cells(1, 10) = Application.Sum(.Parent.Columns(10))
  42.                 .Cells(1, 11) = Application.Sum(.Parent.Columns(11))
  43.                 .Cells(1, 12) = Application.Sum(.Parent.Columns(12))
  44.             End With
  45.         End With
  46.     End With
  47. End Sub
複製代碼
stock

TOP

回復 32# usana642
不好意思沒詳細檢查,更正如下
  1. Option Explicit
  2. Private Sub 更新()
  3.     Dim Rng As Range
  4.     With ActiveSheet
  5.         .Cells.Clear
  6.         With .QueryTables.Add("URL;http://www.taifex.com.tw/chinese/3/3_2_2.asp", ActiveSheet.[A1])
  7.             .WebFormatting = xlWebFormattingNone
  8.             .Refresh BackgroundQuery:=False
  9.             ActiveSheet.Names(.Name).Delete
  10.         End With
  11.         .Range("E:G,I:L,N:Q").Delete                                    '刪除多餘的欄
  12.         .Range("1:6,8:8").Delete                                        '刪除多餘的列
  13.         .Range("B1").End(xlDown).Offset(1).Resize(2).EntireRow.Delete   '刪除多餘的列
  14.         .Range("A:A").Insert                                            '插入一欄
  15.         .[B1].Resize(, 12) = Array("契約", "月份", "履約價", "買賣權", "成交價", "未平倉量", "CALL", "=C2", "call-oi", "put-oi", "call-oi$", "put-oi$")
  16.         '**  "=C2" 可修改為 正確的參照  ***
  17.         With .Range("b2", .[b2].End(xlDown))
  18.             .Offset(, -1) = "=rc4 +rc8 + rc9"
  19.             .Columns(5).Replace "-", ""
  20.             .Columns(7) = "=IF(rc[-3]=""Call"",1,0)"    'R1C1表示法 : 工作表上腧入公式
  21.             .Columns(8) = "=IF(rc[-6]=r1c9,1,8)"
  22.             .Columns(9) = "=IF(rc[-2]=1,rc[-3],0)"
  23.             .Columns(10) = "=IF(rc[-3]=0,rc[-4],0)"
  24.             .Columns(11) = "=if(rc[-1]=0,rc[-6]*rc[-5],"""")"
  25.             .Columns(12) = "=if(rc[-2]<>0,rc[-7]*rc[-6],"""")"
  26.         End With
  27.         .UsedRange.Value = .UsedRange.Value             '消除公式
  28.         .Columns.AutoFit
  29.         Set Rng = .Range("b2", .[b2].End(xlDown))
  30.         With Rng
  31.             .Offset(, -1) = "=rc4 +rc8 + rc9"
  32.             .Columns(5).Replace "-", ""
  33.             .Columns(7) = "=IF(rc[-3]=""Call"",1,0)"    'R1C1表示法 : 工作表上腧入公式
  34.             .Columns(8) = "=IF(rc[-6]=r1c9,1,8)"
  35.             .Columns(9) = "=IF(rc[-2]=1,rc[-3],0)"
  36.             .Columns(10) = "=IF(rc[-3]=0,rc[-4],0)"
  37.             .Columns(11) = "=if(rc[-1]=0,rc[-6]*rc[-5],"""")"
  38.             .Columns(12) = "=if(rc[-2]<>0,rc[-7]*rc[-6],"""")"
  39.              With .Cells(.Rows.Count + 1, 1) '.Rows.Count + 1 範圍內資料總列數+1
  40.                 .Cells(1, 0) = "小計"
  41.                 .Cells(1, 6) = Application.Sum(Rng.Columns(6))
  42.                 .Cells(1, 9) = Application.Sum(Rng.Columns(9))
  43.                 .Cells(1, 10) = Application.Sum(Rng.Columns(10))
  44.                 .Cells(1, 11) = Application.Sum(Rng.Columns(11))
  45.                 .Cells(1, 12) = Application.Sum(Rng.Columns(12))
  46.             End With
  47.         End With
  48.     End With
  49. End Sub
複製代碼

TOP

回復 33# GBKEE


    謝謝GBKEE大大的快速回應,可以正確算出小計了,再次感謝您的熱心協助,祝您週末愉快...
stock

TOP

回復 30# GBKEE
對不起,請教您 "快取圖案格式" 功能欄 我要如何才能找到?
我是 2010 版。因這案例處理或許我會碰上。

TOP

回復 35# c_c_lai
按右鍵

   

TOP

回復 36# GBKEE
真奇,沒看到呦?

又、以下的語法實在是有看沒懂,我一直想了解它們代表的含意:
  1.             .Columns(7) = "=IF(rc[-3]=""Call"",1,0)"        ' R1C1表示法 : 工作表上腧入公式
  2.             .Columns(8) = "=IF(rc[-6]=r1c9,1,8)"
  3.             .Columns(9) = "=IF(rc[-2]=1,rc[-3],0)"
  4.             .Columns(10) = "=IF(rc[-3]=0,rc[-4],0)"
  5.             .Columns(11) = "=if(rc[-1]=0,rc[-6]*rc[-5],"""")"
  6.             .Columns(12) = "=if(rc[-2]<>0,rc[-7]*rc[-6],"""")"
複製代碼
我將 =IF(rc[-3]=""Call"",1,0) 貼到任一欄位想觀察結果,
結果該欄的值卻是整段 =IF(rc[-3]=""Call"",1,0) 之字串。

TOP

本帖最後由 GBKEE 於 2012-10-20 08:50 編輯

回復 37# c_c_lai
會是在 [大小及內容] 中嗎?
FormulaR1C1 屬性   傳回或設定物件的公式,用巨集語言的 R1C1 樣式符號表示。Range 物件為讀/寫 Variant,Series 物件為讀/寫 String。
執行後 如圖 勾選 R1C1  便知

  1. Option Explicit
  2. Sub Ex()
  3.     Dim i
  4.     For i = 1 To 5
  5.         [c5].Cells(1, i) = "=r" & i & "c" & i
  6.         [c5].Cells(2, i) = "=r[" & i & "]c[" & i & "]"
  7.         [c5].Cells(3, i) = "=r[-" & i & "]c[-" & i & "]"
  8.     Next
  9. End Sub
複製代碼

TOP

回復 38# GBKEE
對的!

R1C1 我會好好地去瞭解,謝謝您!

TOP

回復 38# GBKEE

TOP

        靜思自在 : 要批評別人時,先想想自己是否完美無缺。
返回列表 上一主題