返回列表 上一主題 發帖

[發問] 請問如果有一個股票資料庫,如何使用vba…

回復 10# gkld
  1. Option Explicit
  2. Sub Ex()
  3.     Dim Ex_Path As String, Ex_File As String, Ex_Date As String, Ex_Wb As Workbook
  4.     Dim Rng As Range, Ex_Row As Integer, i As Integer ', Ar() As String, Ex_Name As String
  5.     Ex_Path = "C:\Documents and Settings\gkld\桌面\my kp\資料庫\上市\"
  6.     Ex_File = Dir(Ex_Path & "A112*ALL_1.csv")
  7.     If Ex_File = "" Then
  8.         MsgBox "沒有 A112*ALL_1.csv"
  9.         Exit Sub
  10.     End If
  11.     Application.ScreenUpdating = False
  12.     'Ar = Array("台泥", "亞泥", "嘉泥", "幸福", "信大", "東泥")
  13.     For i = 1 To 7
  14.        '** Name 是VBA所用的關鍵字串,避免使用為變數名稱.
  15.        ' If i = 1 Then Ex_Name = "台泥"
  16.        ' If i = 2 Then Ex_Name = "亞泥"
  17.        ' If i = 3 Then Ex_Name = "嘉泥"
  18.        ' If i = 4 Then Ex_Name = "環泥"
  19.        ' If i = 5 Then Ex_Name = "幸福"
  20.        ' If i = 6 Then Ex_Name = "信大"
  21.        ' If i = 7 Then Ex_Name = "東泥"
  22.       
  23.         With Sheets(i)                                                '依工作表索引值指定工作表
  24.         '****工作表名稱 在活頁簿視窗排序如是依IF i=1如此順序***
  25.         '***那就不需這些IF i=1 ...........
  26.       
  27.         'With Sheets(Ex_Name)                                          '依Ex_Name 指定工作表
  28.         '****如在活頁簿視窗工作表名稱排序不是如此順序***
  29.         '***那就需要這些IF i=1 ...........
  30.       
  31.         'With Sheets(Ar(i - 1))                                      '指定定陣列中的工作表名稱
  32.             .Range("a1:ag65536").Clear '消除每一行資料
  33.             Ex_File = Dir(Ex_Path & "A112*ALL_1.csv")
  34.             Do While Ex_File <> ""
  35.                 Ex_Date = Replace(Ex_File, "A112", "")                     '消除檔名中"A112"
  36.                 Ex_Date = Replace(Ex_Date, "ALL_1.csv", "")                '消除檔名中"ALL_1.csv"
  37.                 Ex_Date = DateSerial(Mid(Ex_Date, 1, 4), Mid(Ex_Date, 5, 2), Mid(Ex_Date, 7, 2)) '帶入日期
  38.                
  39.                 Set Ex_Wb = Workbooks.Open(Ex_Path & Ex_File)           '開啟 A11220070102ALL_1.csv.....
  40.                 '************************************************
  41.                 Ex_Row = .Cells(.Rows.Count, "A").End(xlUp).Offset(1).Row '取得資料輸入的列號
  42.                 Set Rng = Ex_Wb.Sheets(1).Range("b:b").Find(.Name, lookat:=xlWhole)
  43.                  '.Cells(Ex_Row, "A") = Ex_Date  '日期輸入         '** 記錄所有日期***
  44.                 If Not Rng Is Nothing Then
  45.                     .Cells(Ex_Row, "A") = Ex_Date '日期輸入  如移到這裡 '** 只記錄有資料的日期
  46.                     .Cells(Ex_Row, "B") = Rng.Offset(, 7)
  47.                     .Cells(Ex_Row, "e") = Rng.Offset(, 4)
  48.                     .Cells(Ex_Row, "f") = Rng.Offset(, 5)
  49.                     .Cells(Ex_Row, "g") = Rng.Offset(, 6)
  50.                     .Cells(Ex_Row, "i") = Rng.Offset(, 1)
  51.                 End If
  52.                 '************************************************
  53.                 Ex_Wb.Close False                                       '關閉 A11220070102ALL_1.csv.....
  54.                 Ex_File = Dir                                               '下一個"A112*ALL_1.csv"
  55.             Loop
  56.         End With
  57.     Next
  58.     Application.ScreenUpdating = True
  59.     MsgBox "OK"
  60. End Sub
複製代碼

TOP

熱心的板大:

怎麼會出現『編譯錯誤,有next卻沒有for』的對話方塊?

我一條一條看程式碼,明明就有for嗎?不就是for i=1 to 7,第13行那兒嗎?

TOP

回復 12# gkld
不好意思…板大…我找到原因了
是我將程式碼日了些東西-____-#
現在改回來,測試沒問題了~
哈哈哈…開心~
感恩丫!!
繼續研究研究 :)

TOP

回復 13# gkld
上傳做好的個股資料圖片,供像我一樣的新手參考
另外提供所談到的資料圖程式 1.rar (17.65 KB)
當然小弟沒有那麼厲害,想當然也是網路上熱心的先進們提供,
雖然日期部分得手動keyin,不過我個人已覺得很滿足了
只要再將板大的指導加進去所得,就可以做出每檔個股歷史資料啦!!

TOP

回復 11# GBKEE
請問板大…
您的這個方式,我用了一陣子
後來發現,如果我有幾筆新最近日期的資料,如A11220130307ALL_1.csv…要放入股票資料庫裡,
執行您教的這個vba的話,它會整個從資料庫裡的每筆舊日期資料重新跑過,挑出來重新排列
這樣很浪費時間
有辦法執行vba的時候,不用再去抓舊日期的資料,只對新筆資料做新增出來作為每日歷史股價嗎?感恩

TOP

回復 15# gkld
試試看
  1. Option Explicit
  2. Sub Ex()
  3.     Dim Ex_Path As String, Ex_File As String, Ex_Date As String, Ex_Wb As Workbook, ar
  4.     Dim Rng As Range, Ex_Row As Integer, i As Integer ', Ar() As String, Ex_Name As String
  5.     Ex_Path = "C:\Documents and Settings\gkld\桌面\my kp\資料庫\上市\"
  6.     Ex_File = Dir(Ex_Path & "A112*ALL_1.csv")
  7.     If Ex_File = "" Then
  8.         MsgBox "沒有 A112*ALL_1.csv"
  9.         Exit Sub
  10.     End If
  11.     Application.ScreenUpdating = False
  12.     ar = Array("台泥", "亞泥", "嘉泥", "幸福", "信大", "東泥")
  13.     For i = 1 To 7
  14.         With Sheets(ar(i - 1))                                      '指定定陣列中的工作表名稱
  15.             .Range("a1:ag65536").Clear '消除每一行資料
  16.             Ex_File = Dir(Ex_Path & "A112*ALL_1.csv")
  17.             Do While Ex_File <> ""
  18.                 Ex_Date = Replace(Ex_File, "A112", "")                     '消除檔名中"A112"
  19.                 Ex_Date = Replace(Ex_Date, "ALL_1.csv", "")                '消除檔名中"ALL_1.csv"
  20.                 Ex_Date = DateSerial(Mid(Ex_Date, 1, 4), Mid(Ex_Date, 5, 2), Mid(Ex_Date, 7, 2)) '帶入日期
  21.                 '*****設下日期條件 一周內的日期
  22.                 If CDate(Ex_Date) + 6 >= Date Then
  23.                     Set Ex_Wb = Workbooks.Open(Ex_Path & Ex_File)           '開啟 A11220070102ALL_1.csv.....
  24.                     Ex_Row = .Cells(.Rows.Count, "A").End(xlUp).Offset(1).Row '取得資料輸入的列號
  25.                     Set Rng = Ex_Wb.Sheets(1).Range("b:b").Find(.Name, lookat:=xlWhole)
  26.                     '.Cells(Ex_Row, "A") = Ex_Date  '日期輸入         '** 記錄所有日期***
  27.                     If Not Rng Is Nothing Then
  28.                         .Cells(Ex_Row, "A") = Ex_Date '日期輸入  如移到這裡 '** 只記錄有資料的日期
  29.                         .Cells(Ex_Row, "B") = Rng.Offset(, 7)
  30.                         .Cells(Ex_Row, "e") = Rng.Offset(, 4)
  31.                         .Cells(Ex_Row, "f") = Rng.Offset(, 5)
  32.                         .Cells(Ex_Row, "g") = Rng.Offset(, 6)
  33.                         .Cells(Ex_Row, "i") = Rng.Offset(, 1)
  34.                     End If
  35.                     Ex_Wb.Close False                                       '關閉 A11220070102ALL_1.csv.....
  36.                 End If   '*****  一周內的日期
  37.                 Ex_File = Dir                                               '下一個"A112*ALL_1.csv"
  38.             Loop
  39.         End With
  40.     Next
  41.     Application.ScreenUpdating = True
  42.     MsgBox "OK"
  43. End Sub
複製代碼

TOP

回復 16# GBKEE
唉呀…板大
我想是我的表達方式讓你誤會成,我只要截取近1週的資料而已
其實是那個股票的資料庫,每天都會有新的資料進來,然後我執行
  1. Option Explicit
  2. Sub Ex()
  3.     Dim Ex_Path As String, Ex_File As String, Ex_Date As String, Ex_Wb As Workbook
  4.     Dim Rng As Range, Ex_Row As Integer, i As Integer ', Ar() As String, Ex_Name As String
  5.     Ex_Path = "C:\Documents and Settings\gkld\桌面\my kp\資料庫\上市\"
  6.     Ex_File = Dir(Ex_Path & "A112*ALL_1.csv")
  7.     If Ex_File = "" Then
  8.         MsgBox "沒有 A112*ALL_1.csv"
  9.         Exit Sub
  10.     End If
  11.     Application.ScreenUpdating = False
  12.     'Ar = Array("台泥", "亞泥", "嘉泥", "幸福", "信大", "東泥")
  13.     For i = 1 To 7
  14.        '** Name 是VBA所用的關鍵字串,避免使用為變數名稱.
  15.        ' If i = 1 Then Ex_Name = "台泥"
  16.        ' If i = 2 Then Ex_Name = "亞泥"
  17.        ' If i = 3 Then Ex_Name = "嘉泥"
  18.        ' If i = 4 Then Ex_Name = "環泥"
  19.        ' If i = 5 Then Ex_Name = "幸福"
  20.        ' If i = 6 Then Ex_Name = "信大"
  21.        ' If i = 7 Then Ex_Name = "東泥"
  22.       
  23.         With Sheets(i)                                                '依工作表索引值指定工作表
  24.         '****工作表名稱 在活頁簿視窗排序如是依IF i=1如此順序***
  25.         '***那就不需這些IF i=1 ...........
  26.       
  27.         'With Sheets(Ex_Name)                                          '依Ex_Name 指定工作表
  28.         '****如在活頁簿視窗工作表名稱排序不是如此順序***
  29.         '***那就需要這些IF i=1 ...........
  30.       
  31.         'With Sheets(Ar(i - 1))                                      '指定定陣列中的工作表名稱
  32.           [s][color=Red]  .Range("a1:ag65536").Clear '消除每一行資料[/color][/s]
  33.             Ex_File = Dir(Ex_Path & "A112*ALL_1.csv")
  34.             Do While Ex_File <> ""
  35.                 Ex_Date = Replace(Ex_File, "A112", "")                     '消除檔名中"A112"
  36.                 Ex_Date = Replace(Ex_Date, "ALL_1.csv", "")                '消除檔名中"ALL_1.csv"
  37.                 Ex_Date = DateSerial(Mid(Ex_Date, 1, 4), Mid(Ex_Date, 5, 2), Mid(Ex_Date, 7, 2)) '帶入日期
  38.                
  39.                 Set Ex_Wb = Workbooks.Open(Ex_Path & Ex_File)           '開啟 A11220070102ALL_1.csv.....
  40.                 '************************************************
  41.                 Ex_Row = .Cells(.Rows.Count, "A").End(xlUp).Offset(1).Row '取得資料輸入的列號
  42.                 Set Rng = Ex_Wb.Sheets(1).Range("b:b").Find(.Name, lookat:=xlWhole)
  43.                  '.Cells(Ex_Row, "A") = Ex_Date  '日期輸入         '** 記錄所有日期***
  44.                 If Not Rng Is Nothing Then
  45.                     .Cells(Ex_Row, "A") = Ex_Date '日期輸入  如移到這裡 '** 只記錄有資料的日期
  46.                     .Cells(Ex_Row, "B") = Rng.Offset(, 7)
  47.                     .Cells(Ex_Row, "e") = Rng.Offset(, 4)
  48.                     .Cells(Ex_Row, "f") = Rng.Offset(, 5)
  49.                     .Cells(Ex_Row, "g") = Rng.Offset(, 6)
  50.                     .Cells(Ex_Row, "i") = Rng.Offset(, 1)
  51.                 End If
  52.                 '************************************************
  53.                 Ex_Wb.Close False                                       '關閉 A11220070102ALL_1.csv.....
  54.                 Ex_File = Dir                                               '下一個"A112*ALL_1.csv"
  55.             Loop
  56.         End With
  57.     Next
  58.     Application.ScreenUpdating = True
  59.     MsgBox "OK"
  60. End Sub
複製代碼
每都都會連同舊的資料一起重抓重跑,時間秏費不少
我想要的結果是之前執行後的舊資料會留著,每當我有一筆新資料進來時,就只要跑新的資料新增就好
因為我vb不好,沒法子像板大一樣,可以寫出比對資料庫裡的data,只把新進來的data抓出來,
後來剛吃晚餐時,突然想到另一個解決方式
我將新的data放進另一個新的資料夾,然後不要消除每一行的資料,即執行以下程式碼
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 ', Ar() As String, Ex_Name As String
    Ex_Path = "C:\Documents and Settings\gkld\桌面\my kp\資料庫\新資料夾\"
    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
    'Ar = Array("台泥", "亞泥", "嘉泥", "幸福", "信大", "東泥")
    For i = 1 To 7
       '** Name 是VBA所用的關鍵字串,避免使用為變數名稱.
       ' If i = 1 Then Ex_Name = "台泥"
       ' If i = 2 Then Ex_Name = "亞泥"
       ' If i = 3 Then Ex_Name = "嘉泥"
       ' If i = 4 Then Ex_Name = "環泥"
       ' If i = 5 Then Ex_Name = "幸福"
       ' If i = 6 Then Ex_Name = "信大"
       ' If i = 7 Then Ex_Name = "東泥"
      
        With Sheets(i)                                                '依工作表索引值指定工作表
        '****工作表名稱 在活頁簿視窗排序如是依IF i=1如此順序***
        '***那就不需這些IF i=1 ...........
      
        'With Sheets(Ex_Name)                                          '依Ex_Name 指定工作表
        '****如在活頁簿視窗工作表名稱排序不是如此順序***
        '***那就需要這些IF i=1 ...........
      
        'With Sheets(Ar(i - 1))                                      '指定定陣列中的工作表名稱
            .Range("a1:ag65536").Clear '消除每一行資料
            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)) '帶入日期
               
                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("b:b").Find(.Name, lookat:=xlWhole)
                 '.Cells(Ex_Row, "A") = Ex_Date  '日期輸入         '** 記錄所有日期***
                If Not Rng Is Nothing Then
                    .Cells(Ex_Row, "A") = Ex_Date '日期輸入  如移到這裡 '** 只記錄有資料的日期
                    .Cells(Ex_Row, "B") = Rng.Offset(, 7)
                    .Cells(Ex_Row, "e") = Rng.Offset(, 4)
                    .Cells(Ex_Row, "f") = Rng.Offset(, 5)
                    .Cells(Ex_Row, "g") = Rng.Offset(, 6)
                    .Cells(Ex_Row, "i") = Rng.Offset(, 1)
                End If
                '************************************************
                Ex_Wb.Close False                                       '關閉 A11220070102ALL_1.csv.....
                Ex_File = Dir                                               '下一個"A112*ALL_1.csv"
            Loop
        End With
    Next
    Application.ScreenUpdating = True
    MsgBox "OK"
End Sub
好像也可以解決
唉…只能用笨方法了

TOP

回復 17# gkld
你的修改可能還是不可以 因這行  .Range("a1:ag65536").Clear   '會消除所有的舊資料
試試看
  1. Option Explicit
  2. Sub Ex()
  3.     Dim Ex_Path As String, Ex_File As String, Ex_Date As String, Ex_Wb As Workbook
  4.     Dim Rng As Range, Ex_Row As Integer, i As Integer
  5.     Dim Ar() As String, Wb As Workbook
  6.     'Set Wb = Workbooks.Open("D:\股票資料庫.xls")    '開啟股票資料庫的活頁簿
  7.     Ex_Path = "C:\Documents and Settings\gkld\桌面\my kp\資料庫\上市\"
  8.    
  9.     Ex_File = Dir(Ex_Path & "A112*ALL_1.csv")
  10.     If Ex_File = "" Then
  11.         MsgBox "沒有 A112*ALL_1.csv"
  12.         Exit Sub
  13.     End If
  14.     Application.ScreenUpdating = False
  15.     Ar = Array("台泥", "亞泥", "嘉泥", "幸福", "信大", "東泥")
  16.     Ex_File = Dir(Ex_Path & "A112*ALL_1.csv")
  17.     Do While Ex_File <> ""
  18.         Ex_Date = Replace(Ex_File, "A112", "")                     '消除檔名中"A112"
  19.         Ex_Date = Replace(Ex_Date, "ALL_1.csv", "")                '消除檔名中"ALL_1.csv"
  20.         Ex_Date = DateSerial(Mid(Ex_Date, 1, 4), Mid(Ex_Date, 5, 2), Mid(Ex_Date, 7, 2)) '帶入日期-> Ex_Date
  21.         For i = 1 To 7
  22.             With Sheets(Ar(i - 1))                                      '指定定陣列中的工作表名稱
  23.             'With Wb.Sheets(Ar(i - 1))                                 '指定定陣列中的工作表不在此程序專案的活頁簿中
  24.                 If Not .Columns(1).Find(CDate(Ex_Date), LookIn:=xlFormulas) Is Nothing Then Exit For
  25.                 '***  不再重複舊有資料  ****'CDate(Ex_Date)日期 -> 工作表A欄中 找到日期(有):離開回圈
  26.                 'CDate函數   Date任何可使用的日期運算式。

  27.                 Set Ex_Wb = Workbooks.Open(Ex_Path & Ex_File)           '開啟 A11220070102ALL_1.csv.....
  28.                 '************************************************
  29.                 Ex_Row = .Cells(.Rows.Count, "A").End(xlUp).Offset(1).Row '取得資料輸入的列號
  30.                 Set Rng = Ex_Wb.Sheets(1).Range("b:b").Find(.Name, LookAt:=xlWhole)
  31.                  '.Cells(Ex_Row, "A") = Ex_Date  '日期輸入         '** 記錄所有日期***
  32.                 If Not Rng Is Nothing Then
  33.                     .Cells(Ex_Row, "A") = Ex_Date '日期輸入  如移到這裡 '** 只記錄有資料的日期
  34.                     .Cells(Ex_Row, "B") = Rng.Offset(, 7)
  35.                     .Cells(Ex_Row, "e") = Rng.Offset(, 4)
  36.                     .Cells(Ex_Row, "f") = Rng.Offset(, 5)
  37.                     .Cells(Ex_Row, "g") = Rng.Offset(, 6)
  38.                     .Cells(Ex_Row, "i") = Rng.Offset(, 1)
  39.                 End If
  40.             End With
  41.             Ex_Wb.Close False                                       '關閉 A11220070102ALL_1.csv.....
  42.             Ex_File = Dir                                               '下一個"A112*ALL_1.csv"
  43.         Next
  44.     Loop
  45.     Application.ScreenUpdating = True
  46.     MsgBox "OK"
  47. End Sub
複製代碼

TOP

回復 18# GBKEE
呀…
板主說的沒有錯,因這行  .Range("a1:ag65536").Clear   '會消除所有的舊資料,我昨晚有把它刪除
試過這樣是可以,昨晚我po的程式碼,忘了把這行改掉,只要將消除所有的舊資料的程式碼那行拿掉,透過用兩個資料夾的方式還是有成功

我現在來試試板的方法看看~

TOP

回復 18# GBKEE
板大…如果程式碼如下
  1. Sub Ex()
  2.     Dim Ex_Path As String, Ex_File As String, Ex_Date As String, Ex_Wb As Workbook
  3.     Dim Rng As Range, Ex_Row As Integer, i As Integer ', Ar() As String, Ex_Name As String
  4.     Ex_Path = "C:\Documents and Settings\gkld\桌面\my kp\資料庫\old 上市\"
  5.     Ex_File = Dir(Ex_Path & "A112*ALL_1.csv")
  6.     If Ex_File = "" Then
  7.         MsgBox "沒有 A112*ALL_1.csv"
  8.         Exit Sub
  9.     End If
  10.     Application.ScreenUpdating = False
  11.     'Ar = Array("台泥", "亞泥", "嘉泥", "幸福", "信大", "東泥")
  12.     For i = 2 To 8
  13.        '** Name 是VBA所用的關鍵字串,避免使用為變數名稱.
  14.        ' If i = 1 Then Ex_Name = "台泥"
  15.        ' If i = 2 Then Ex_Name = "亞泥"
  16.        ' If i = 3 Then Ex_Name = "嘉泥"
  17.        ' If i = 4 Then Ex_Name = "環泥"
  18.        ' If i = 5 Then Ex_Name = "幸福"
  19.        ' If i = 6 Then Ex_Name = "信大"
  20.        ' If i = 7 Then Ex_Name = "東泥"
  21.       
  22.         With Sheets(i)                                                '依工作表索引值指定工作表
  23.         '****工作表名稱 在活頁簿視窗排序如是依IF i=1如此順序***
  24.         '***那就不需這些IF i=1 ...........
  25.       
  26.         'With Sheets(Ex_Name)                                          '依Ex_Name 指定工作表
  27.         '****如在活頁簿視窗工作表名稱排序不是如此順序***
  28.         '***那就需要這些IF i=1 ...........
  29.       
  30.         'With Sheets(Ar(i - 1))                                      '指定定陣列中的工作表名稱
  31.             .Range("m1:ag65536").Clear '消除每一行資料
  32.             .Range("a1") = "日期"           '製作表頭
  33.             .Range("b1") = "收盤"
  34.             .Range("c1") = "漲跌"
  35.             .Range("d1") = "漲跌率"
  36.             .Range("e1") = "開盤"
  37.             .Range("f1") = "最高"
  38.             .Range("g1") = "最低"
  39.             .Range("h1") = "成交量(單位)"
  40.             .Range("i1") = "成交量"
  41.             Ex_File = Dir(Ex_Path & "A112*ALL_1.csv")
  42.             Do While Ex_File <> ""
  43.                 Ex_Date = Replace(Ex_File, "A112", "")                     '消除檔名中"A112"
  44.                 Ex_Date = Replace(Ex_Date, "ALL_1.csv", "")                '消除檔名中"ALL_1.csv"
  45.                 Ex_Date = DateSerial(Mid(Ex_Date, 1, 4), Mid(Ex_Date, 5, 2), Mid(Ex_Date, 7, 2)) '帶入日期
  46.          If .Columns(1).Find(CDate(Ex_Date), LookIn:=xlFormulas) Is Nothing Then Ex_File = Dir
  47.          '***  不再重複舊有資料 ****'CD(EX_Date)日期->工作表A欄中找到日期間(有):離開回圈
  48.          
  49.          
  50.                     Set Ex_Wb = Workbooks.Open(Ex_Path & Ex_File)           '開啟 A11220070102ALL_1.csv.....
  51.                 '************************************************
  52.                 Ex_Row = .Cells(.Rows.Count, "A").End(xlUp).Offset(1).Row '取得資料輸入的列號
  53.                 Set Rng = Ex_Wb.Sheets(1).Range("a:a").Find(.Name, lookat:=xlWhole)
  54.                  '.Cells(Ex_Row, "A") = Ex_Date  '日期輸入         '***記錄所有日期***
  55.                 If Not Rng Is Nothing Then
  56.                     .Cells(Ex_Row, "A") = Ex_Date '日期輸入  如移到這裡 '** 只記錄有資料的日期
  57.                     .Cells(Ex_Row, "B") = Rng.Offset(, 8)
  58.                     .Cells(Ex_Row, "e") = Rng.Offset(, 5)
  59.                     .Cells(Ex_Row, "f") = Rng.Offset(, 6)
  60.                     .Cells(Ex_Row, "g") = Rng.Offset(, 7)
  61.                     .Cells(Ex_Row, "i") = Rng.Offset(, 2)
  62.                 End If
  63.                 '************************************************
  64.                 Ex_Wb.Close False                                       '關閉 A11220070102ALL_1.csv.....
  65.       
  66.                 Ex_File = Dir                                               '下一個"A112*ALL_1.csv"
  67.             Loop
  68.         End With
  69.     Next
  70.     Application.ScreenUpdating = True
  71.     MsgBox "OK"
  72. End Sub
複製代碼
那麼

         If .Columns(1).Find(CDate(Ex_Date), LookIn:=xlFormulas) Is Nothing Then Ex_File = Dir
         '***  不再重複舊有資料 ****'CD(EX_Date)日期->工作表A欄中找到日期間(有):離開回圈

該放在哪兒,才能執行成功?

TOP

        靜思自在 : 盡多少本份,就得多少本事。
返回列表 上一主題