- 帖子
- 44
- 主題
- 7
- 精華
- 0
- 積分
- 51
- 點名
- 0
- 作業系統
- XP
- 軟體版本
- XP
- 閱讀權限
- 20
- 註冊時間
- 2012-11-18
- 最後登錄
- 2022-8-6

|
回復 20# gkld - Option Explicit
- Sub Ex()
- Dim Ex_Path As String, Ex_File As String, Ex_Date As String, Ex_Wb As Workbook
- Dim Rng As Range, Ex_Row As Integer, i As Integer
- Ex_Path = "C:\Documents and Settings\gkld\桌面\my kp\資料庫\old 上市\"
- Ex_File = Dir(Ex_Path & "A112*ALL_1.csv")
- If Ex_File = "" Then
- MsgBox "沒有 A112*ALL_1.csv"
- Exit Sub
- End If
- Application.ScreenUpdating = False
-
- For i = 2 To 8
-
- With Sheets(i)
-
- .Range("a1") = "日期" '製作表頭
- .Range("b1") = "收盤"
- .Range("c1") = "漲跌"
- .Range("d1") = "漲跌率"
- .Range("e1") = "開盤"
- .Range("f1") = "最高"
- .Range("g1") = "最低"
- .Range("h1") = "成交量(單位)"
- .Range("i1") = "成交量"
- Ex_File = Dir(Ex_Path & "A112*ALL_1.csv")
- Do While Ex_File <> ""
- Ex_Date = Replace(Ex_File, "A112", "") '消除檔名中"A112"
- Ex_Date = Replace(Ex_Date, "ALL_1.csv", "") '消除檔名中"ALL_1.csv"
- Ex_Date = DateSerial(Mid(Ex_Date, 1, 4), Mid(Ex_Date, 5, 2), Mid(Ex_Date, 7, 2)) '帶入日期
- If Not .Columns(1).Find(CDate(Ex_Date), LookIn:=xlFormulas) Is Nothing Then Exit For
- '*** 不再重複舊有資料 ****'CDate(Ex_Date)日期 -> 工作表A欄中 找到日期(有):離開回圈
- 'CDate函數 Date任何可使用的日期運算式。
- Set Ex_Wb = Workbooks.Open(Ex_Path & Ex_File) '開啟 A11220070102ALL_1.csv.....
- '************************************************
- Ex_Row = .Cells(.Rows.Count, "A").End(xlUp).Offset(1).Row '取得資料輸入的列號
- Set Rng = Ex_Wb.Sheets(1).Range("a:a").Find(.Name, LookAt:=xlWhole)
-
- If Not Rng Is Nothing Then
- .Cells(Ex_Row, "A") = Ex_Date '日期輸入 如移到這裡 '** 只記錄有資料的日期
- .Cells(Ex_Row, "B") = Rng.Offset(, 8)
- .Cells(Ex_Row, "e") = Rng.Offset(, 5)
- .Cells(Ex_Row, "f") = Rng.Offset(, 6)
- .Cells(Ex_Row, "g") = Rng.Offset(, 7)
- .Cells(Ex_Row, "i") = Rng.Offset(, 2)
- End If
- '************************************************
- Ex_Wb.Close False '關閉 A11220070102ALL_1.csv.....
- ' End If '*****一周內的日期
- Ex_File = Dir '下一個"A112*ALL_1.csv"
- Loop
- End With
- Next
- Application.ScreenUpdating = True
- MsgBox "OK"
- End Sub
複製代碼 放的位置如上,我執行的時候,就直接跳出我的i=2 to 8 這個回圈了
該如何解決? |
|