返回列表 上一主題 發帖

[發問] Excel VBA 條件成立後,存檔時提醒

  1. Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
  2. Dim d As Date, a, b, r&, c&, t As Boolean
  3. r = [c1].CurrentRegion.Rows.Count - 1
  4. c = Columns("aj").Column
  5. a = Cells(2, 1).Resize(r, c).Value
  6. b = Cells(2, "aq").Resize(r).Value
  7. For i = 1 To UBound(a)
  8.     d = a(i, 3)
  9.     If a(i, c - 1) > a(i, c) Then b(i, 1) = "帳面錯誤": If d = Date Then t = True
  10. Next
  11. Cells(2, "aq").Resize(r) = b
  12. If t Then MsgBox "請注意" & Date & "帳面錯誤"
  13. End Sub
複製代碼

TOP

不明白! 請列出問題,模擬要求結果。

TOP

  1. Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
  2. Dim d As Date, a, b, r&, c&, t As Boolean
  3. r = [c1].CurrentRegion.Rows.Count - 1
  4. c = Columns("aj").Column
  5. a = Cells(2, 1).Resize(r, c).Value
  6. b = Cells(2, "aq").Resize(r).Value
  7. d = Application.Max(Cells(2, 3).Resize(r))
  8. For i = 1 To UBound(a)
  9.     If a(i, c - 1) > a(i, c) Then b(i, 1) = "帳面錯誤": If d = a(i, 3) Then t = True
  10. Next
  11. Cells(2, "aq").Resize(r) = b
  12. If t Then MsgBox "請注意" & d & "帳面錯誤"
  13. End Sub
複製代碼

TOP

        靜思自在 : 能幹不幹,不如苦幹實幹。
返回列表 上一主題