返回列表 上一主題 發帖

[發問] 請問該如何自動記錄加總

回復 1# leefing
  1. Sub RR()
  2. Range(Cells(2, "T"), Cells([A65536].End(xlUp).Row, "U")) = ""
  3. For X = 2 To [A65536].End(xlUp).Row
  4.   If Cells(X, "J") >= 10 Then
  5.      If (Cells(X, "F") = Cells(X, "D")) Then
  6.        Cells(X, "U") = "空"
  7.      End If
  8.      If (Cells(X, "F") = Cells(X, "E")) Then
  9.        Cells(X, "T") = "多"
  10.      End If
  11.      If (Cells(X, "F") > Cells(X, "D")) And (Cells(X, "F") > Cells(X, "E")) Then
  12.        Cells(X, "T") = Cells(X, "T") & "多"
  13.      End If
  14.      If (Cells(X, "F") < Cells(X, "D")) And (Cells(X, "F") < Cells(X, "E")) Then
  15.        Cells(X, "U") = Cells(X, "U") & "空"
  16.      End If
  17.    End If
  18. Next X
複製代碼
是這樣嗎?
不了解 每次出現  就累加上次,而不會取代掉?

TOP

回復 3# leefing

工作表模組
  1. Private Sub WORKSHEET_CHANGE(ByVal TARGET As Range)
  2. If TARGET.Address = "$J$2" And Cells(2, "J") >= 10 Then
  3. X = Cells(2, "U")
  4. Y = Cells(2, "T")
  5.   If Cells(2, "J") >= 10 Then
  6.      If (Cells(2, "F") = Cells(2, "D")) Then
  7.        Cells(2, "U") = Cells(2, "J") + X
  8.      End If
  9.      If (Cells(2, "F") = Cells(2, "E")) Then
  10.        Cells(2, "T") = Cells(2, "J") + Y
  11.      End If
  12.      If (Cells(2, "F") > Cells(2, "D")) And (Cells(2, "F") > Cells(2, "E")) Then
  13.        Cells(2, "T") = Cells(2, "J") + Y
  14.      End If
  15.      If (Cells(2, "F") < Cells(2, "D")) And (Cells(2, "F") < Cells(2, "E")) Then
  16.        Cells(2, "U") = Cells(2, "J") + X
  17.      End If
  18.    End If
  19. End If
  20. End Sub
複製代碼

TOP

回復 5# leefing

工作表模組
程式只會作用在該工作表
若另一工作表也須相同之功能,則該工作表模組也要有相同之程式

例
sheet1工作表模組放上述之程式
sheet2工作表模組放上述之程式

TOP

回復 7# leefing

各工作表模組之程式是互不相干的(獨立的)
要用相同的變數名稱也沒關係

TOP

回復 23# appr

1.gif

工作表模組
  1. Private Sub Worksheet_Change(ByVal Target As Range)
  2. If Target.Address = "$A$2" And [A2] <> "" Then
  3.    [C2] = [C2] + [A2]
  4.    [A2] = ""
  5. End If
  6. If Target.Address = "$B$2" And [B2] <> "" Then
  7.    [C2] = [C2] - [B2]
  8.    [B2] = ""
  9. End If
  10. End Sub
複製代碼

TOP

回復 26# appr

工作表模組
  1. Private Sub Worksheet_Change(ByVal Target As Range)
  2. Set RngA = Range("A2:A4")
  3. Set RngB = Range("B2:B4")
  4. Set RngCA = Intersect(Target, RngA)
  5. Set RngCS = Intersect(Target, RngB)
  6. If Not RngCA Is Nothing Then
  7.    RngCA.Offset(0, 2) = RngCA.Offset(0, 2) + RngCA.Value
  8.    RngCA.Value = ""
  9. End If
  10. If Not RngCS Is Nothing Then
  11.    RngCS.Offset(0, 1) = RngCS.Offset(0, 1) - RngCS.Value
  12.    RngCS.Value = ""
  13. End If
  14. End Sub
複製代碼

TOP

回復 28# appr

只放27#的程式碼
放在工作表模組,如下圖

還有問題的話,請上傳檔案

TOP

        靜思自在 : 君子如水,隨方就圓,無處不自在。
返回列表 上一主題