設萬維讀者為首頁 廣告服務 技術服務 聯繫我們 關於萬維
簡體 繁體 手機版
分類廣告
版主:
萬維讀者網 > 靈機一動 > 跟帖
Search "Excel Event Handler"
送交者: 零加一中 2009月04月08日07:43:02 於 [靈機一動] 發送悄悄話
回  答: 能否把答案貼過來,謝謝。俠行天涯 於 2009-04-07 17:16:16
in Google. There is a article giving detailed solution.
--------------------------------------------------------------
An event handler is associated with just a single worksheet. Start from that worksheet and hit alt-F11 to open the VB editor.
In the upper left window (Project - VBA Project) double click the name of your worksheet.
In the right pane, click the left drop down and change general to Worksheet.
In the right drop down, pick Change.
This will cause Excel to pre-enter the following macro shell for you:

Private Sub Worksheet_Change(ByVal Target As Range)
UserInput = Target.Value
If UserInput > 1 Then
NewInput = Left(UserInput, Len(UserInput) - 2) & ":" & Right(UserInput, 2)
Application.EnableEvents = False
Target = NewInput
Application.EnableEvents = True
End If
End Sub
Any time a cell is changed, the cell that was changed is passed to this program in the variable called "Target". When someone enters a time with a colon in the worksheet, it will evaluate to a number less than one. The If block makes sure to only change cells if they are greater than one. I use the left() and right() functions to break the user input into hours and minutes and insert a colon in between.

Whenever the user enters "2345", the program will change this entry to 23:45.
0%(0)
0%(0)
標  題 (必選項):
內  容 (選填項):
實用資訊
回國機票$360起 | 商務艙省$200 | 全球最佳航空公司出爐:海航獲五星
海外華人福利!在線看陳建斌《三叉戟》熱血歸回 豪情築夢 高清免費看 無地區限制
一周點擊熱帖 更多>>
一周回復熱帖
歷史上的今天:回復熱帖
2008: 數學題: 摺紙
2008: 簡單球面幾何問題