返回列表 上一主題 發帖

[發問] 如何將DEE連結到Excel的資料,依照想要的時間記錄下來.

可能重新佈署一下會好一點
新增一般模組
輸入程式碼
  1. Public i%
  2. Sub auto_open()
  3. With Sheet2
  4. k = .[IV1].End(xlToLeft).Column
  5. i = IIf(k = 1, 0, k - 3)
  6. If i = 0 Then .[A1:C1].Value = Sheet1.[A1:C1].Value
  7. End With
  8. End Sub
複製代碼
Sheet1模組
  1. Private Sub Worksheet_Calculate() '這是Sheet1預設的重算觸動事件程式
  2.     Dim A As Range
  3.     'Static 陳述式  在程序層次中用來宣告變數並配置儲存空間。以 Static 陳述式宣告的變數,在程式執行期間,會一直保留內容。
  4.      With Sheet2
  5.      Set A = .Cells(65536, i + 1).End(xlUp).Offset(1).Resize(, 3)
  6.      If A.Row > 100 Then i = i + 3: .Cells(1, i + 1).Resize(, 3) = [A1:C1].Value '到第100列時右移3欄
  7.      Set A = .Cells(65536, i + 1).End(xlUp).Offset(1).Resize(, 3)
  8.        If A.Cells(1, 3).Offset(-1) <> [C2] Then   '成交價有異動時的條件成立時
  9.             A.Value = [A2:C2].Value                '將Shse1的日期,時間,成交價記錄到Sheet2
  10.        End If
  11.     End With
  12. End Sub
複製代碼
紀錄.zip (10.81 KB)
學海無涯_不恥下問

TOP

本帖最後由 Hsieh 於 2010-11-17 18:13 編輯

此時的DDE是否還未傳入數據造成A2:C2出現錯誤值所致
  1. Private Sub Worksheet_Calculate() '這是Sheet1預設的重算觸動事件程式
  2.     Dim A As Range
  3.     'Static 陳述式  在程序層次中用來宣告變數並配置儲存空間。以 Static 陳述式宣告的變數,在程式執行期間,會一直保留內容。
  4.      With Sheet2
  5.      Set A = .Cells(65536, i + 1).End(xlUp).Offset(1).Resize(, 3)
  6.      If A.Row > 100 Then i = i + 3: .Cells(1, i + 1).Resize(, 3) = [A1:C1].Value '到第100列時右移3欄
  7.      Set A = .Cells(65536, i + 1).End(xlUp).Offset(1).Resize(, 3)
  8.      If IsError([C2].Value) Then Exit Sub
  9.        If A.Cells(1, 3).Offset(-1) <> [C2] Then   '成交價有異動時的條件成立時
  10.             A.Value = [A2:C2].Value                '將Shse1的日期,時間,成交價記錄到Sheet2
  11.        End If
  12.     End With
  13. End Sub
複製代碼
學海無涯_不恥下問

TOP

你試著錄製A2:C2插入儲存格
再填入就行了
學海無涯_不恥下問

TOP

回復 14# aries
  1. Private Sub Worksheet_Calculate() '這是Sheet1預設的重算觸動事件程式
  2.     Dim A As Range
  3.      With Sheet2
  4.      .[A2:C2].Insert xlShiftDown
  5.      Set A = .Cells(2, 1).Resize(, 3)
  6.      If A.Row > 100 Then i = i + 3: .Cells(1, i + 1).Resize(, 3) = [A1:C1].Value '到第100列時右移3欄
  7.      Set A = .Cells(2, i + 1).Resize(, 3)
  8.      If IsError([C2].Value) Then Exit Sub
  9.        If .[C3] <> [C2] Then   '成交價有異動時的條件成立時
  10.             A.Value = [A2:C2].Value '將Shse1的日期,時間,成交價記錄到Sheet2
  11.             Else
  12.             .[A2:C2].Delete xlShiftUp '未異動價格就刪除插入的
  13.        End If
  14.     End With
  15. End Sub
複製代碼
學海無涯_不恥下問

TOP

回復 16# aries
  1. Private Sub Worksheet_Calculate() '這是Sheet1預設的重算觸動事件程式
  2.     Dim A As Range
  3.      If IsError([C2].Value) Then Exit Sub
  4.      With Sheet2
  5.      i = .[IV1].End(xlToLeft).Column - 2
  6.        'If .[C3] <> [C2] Then   '成交價有異動時的條件成立時
  7.           If .Cells(65536, i).End(xlUp).Row = 100 Then i = i + 3: .Cells(1, i).Resize(, 3).Value = [A1:C1].Value
  8.           .Cells(2, i).Resize(, 3).Insert xlShiftDown
  9.           .Cells(2, i).Resize(, 3) = [A2:C2].Value '將Shse1的日期,時間,成交價記錄到Sheet2
  10.        'End If
  11.     End With
  12. End Sub
複製代碼
學海無涯_不恥下問

TOP

        靜思自在 : 愛不是要求對方,而是要由自身的付出。
返回列表 上一主題