返回列表 上一主題 發帖

變動紀錄的程式

存檔後 檔案記得關閉在重開

TOP

改成這樣

    Sub RecordPrice()
Dim WR As Long
Dim I As Byte

Dim DDE_總量 As Range
Set DDE_總量 = Range("D2")
   
If IsError(DDE_總量.Value) Then Exit Sub
If DDE_總量.Value <= 0 Then Exit Sub

WR = DDE_總量.CurrentRegion.Row + DDE_總量.CurrentRegion.Rows.Count
'ActiveWindow.ScrollRow = WR - 5 '只顯示最新幾筆資料
If (WR = 3) Or _
   (Cells(WR - 1, DDE_總量.Column) <> DDE_總量.Value) Then       '總量有異動時才記錄

    Excel.Application.EnableEvents = 0

    Cells(WR, DDE_總量.Column).Offset(, -1).Resize(, 3).Value = _
                      DDE_總量.Offset(, -1).Resize(, 3).Value

    Excel.Application.EnableEvents = 1
End If

End Sub

TOP

除錯 - 複製.rar (35.1 KB) 回復 11# jackyq


    請大大看看

TOP

有可能執行到 Excel.Application.EnableEvents = 0 時
還沒執行到 Excel.Application.EnableEvents = 1 就貝你中途 Stop 掉
那你的事件就不會在觸發
OR 其他原因.... 沒檔案沒真相

TOP

回復 9# jackyq

這個,我甚麼都沒改
    Sub RecordPrice()
Dim WR As Long
Dim I As Byte

Excel.Application.EnableEvents = 0

Dim DDE_總量 As Range
Set DDE_總量 = Range("D2")
   
If IsError(DDE_總量.Value) Then Exit Sub
If DDE_總量.Value <= 0 Then Exit Sub

WR = DDE_總量.CurrentRegion.Row + DDE_總量.CurrentRegion.Rows.Count
'ActiveWindow.ScrollRow = WR - 5 '只顯示最新幾筆資料
If (WR = 3) Or _
   (Cells(WR - 1, DDE_總量.Column) <> DDE_總量.Value) Then       '總量有異動時才記錄
    Cells(WR, DDE_總量.Column).Offset(, -1).Resize(, 3).Value = _
                      DDE_總量.Offset(, -1).Resize(, 3).Value
End If

Excel.Application.EnableEvents = 1
End Sub

TOP

哪個版本? ..............

TOP

本帖最後由 藍天麗池 於 2016-3-22 09:05 編輯

回復 7# jackyq
C大我了解了,感謝妳我試試看
可是用你的版本我測試是沒有動作的

TOP

本帖最後由 jackyq 於 2016-3-22 08:41 編輯

因為你說你要換位置ㄚ
原本總量的 DDE 在  B2 那就寫成 Set DDE_總量 = Range("B2")
如果總量的 DDE 搬到  D2 那就寫成 Set DDE_總量 = Range("D2")
其他的都不用改
如果堅持用原先那個
每次換位置就要修改不少地方


Sub RecordPrice()
Dim WR As Long
Dim I As Byte


If Range("F2") < 1 Then Exit Sub

Excel.Application.EnableEvents = 0

WR = Range("C1").End(xlDown).Row + 1
'ActiveWindow.ScrollRow = WR - 5 '只顯示最新幾筆資料
If (WR = 3) Or _
   (Range("D" & WR - 1) <> Range("D2")) Then '總量有異動時才記錄
    For I = 3 To 5
    Cells(WR, I) = Cells(2, I)
    Next
End If


Excel.Application.EnableEvents = 1

'For I = 1 To 10
'   Cells(WR, I) = Cells(2, I)
'Next 'I
End Sub

TOP

本帖最後由 藍天麗池 於 2016-3-22 08:43 編輯

回復 5# jackyq

J大,裡面的(DDE_總量),是要用甚麼替換嗎,我看不太懂是甚麼意思??
可以幫我說明一下嗎??
我原附件裡面沒有這個東西,感謝你喔

測試後沒有動作

TOP

不不, 我不厲害, 這個其他大大都知道, 他們忙而已


Sub RecordPrice()
Dim WR As Long
Dim I As Byte

Excel.Application.EnableEvents = 0

Dim DDE_總量 As Range
Set DDE_總量 = Range("D2")
   
If IsError(DDE_總量.Value) Then Exit Sub
If DDE_總量.Value <= 0 Then Exit Sub

WR = DDE_總量.CurrentRegion.Row + DDE_總量.CurrentRegion.Rows.Count
'ActiveWindow.ScrollRow = WR - 5 '只顯示最新幾筆資料
If (WR = 3) Or _
   (Cells(WR - 1, DDE_總量.Column) <> DDE_總量.Value) Then       '總量有異動時才記錄
    Cells(WR, DDE_總量.Column).Offset(, -1).Resize(, 3).Value = _
                      DDE_總量.Offset(, -1).Resize(, 3).Value
End If

Excel.Application.EnableEvents = 1
End Sub

TOP

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