返回列表 上一主題 發帖

[發問] 使用陣列代碼帶入股票

[發問] 使用陣列代碼帶入股票

各位前輩 我想要把陣列加入資料 ,讓9946可以帶入我所定義股票列表...
如紅色區塊

9946-->取代成StockArr..

Dim StockArr As variable
StockArr = Array(9946,2330,2317,5522)'等等的股票



Dim E As Object, i As Integer, ii As Integer, k As Integer
    Dim xadte As Date
    xadte = DateAdd("yyyy", -1, Date)  '日期(起):
    With CreateObject("InternetExplorer.Application")
        .Visible = True
        .Navigate "http://www.cnyes.com/twstock/intro/9946.htm"
        Do While .Busy Or .ReadyState <> 4: DoEvents: Loop
        Set E = .document.getElementsByTAGName("TABLE")(4)
        ActiveSheet.UsedRange.Clear
        For i = 0 To E.Rows.Length - 1
            k = k + 1
            For ii = 0 To E.Rows(i).Cells.Length - 1
                Cells(k, ii + 1) = E.Rows(i).Cells(ii).INNERTEXT
            Next
        Next
        .Quit        '關閉網頁
    End With
   
    Dim yadte As Date
    yadte = DateAdd("yyyy", -1, Date)  '日期(起):
    With CreateObject("InternetExplorer.Application")
        .Visible = True
        .Navigate "http://pchome.megatime.com.tw/stock/9946.html"
        Do While .Busy Or .ReadyState <> 4: DoEvents: Loop
        Set E = .document.getElementsByTAGName("TABLE")(4)
        For i = 0 To E.Rows.Length - 1
            k = k + 1
            For ii = 0 To E.Rows(i).Cells.Length - 1
                Cells(k, ii + 1) = E.Rows(i).Cells(ii).INNERTEXT
            Next
        Next
        .Quit        '關閉網頁
    End With
       
       
        Dim R As Range, Rng As Range
    For Each R In ActiveSheet.Range("A:A").SpecialCells(xlCellTypeConstants).Rows
    'ActiveSheet(作用工作表) SpecialCells(xlCellTypeConstants "包含常數的儲存格")
         If Not IsError(Application.Match("相關權證", R, 0)) Then
            '工作表函數Match 尋找到0 傳回數字,找不到0 傳回錯誤值 #N/A
            If Rng Is Nothing Then Set Rng = R Else Set Rng = Union(R, Rng)
            'Union 方法 傳回兩個或多個範圍的合併範圍。
        End If
   Next
   If Not Rng Is Nothing Then Rng.EntireRow.Delete   '範圍整欄刪除

2014-12-28-Stock.rar (20.2 KB)

回復 3# GBKEE

GBKEE 前輩你好
我想在加上一個陣列表,當儲存格有找到Array的清單就把該ROW刪除..
Array = {漲跌,本益比,同業,平均本益比,總市值,投資報酬率,今年以來,最近一週,最近,一個月}
附上另一個檔案....

再麻煩您了...非常感謝...

Stock_20141229.rar (21.02 KB)

TOP

回復 5# GBKEE


    感謝GBKEE大大 !! 我已經加入程式碼中了 感謝您的大力幫忙

TOP

        靜思自在 : 難行能行,難捨能捨,難為能為,才能昇華自我的人格。
返回列表 上一主題