设万维读者为首页 广告服务 技术服务 联系我们 关于万维
简体 繁体 手机版
分类广告
版主:
万维读者网 > 灵机一动 > 帖子
零加一中:Excel问题解答
送交者: 侠行天涯 2009年04月12日10:09:44 于 [灵机一动] 发送悄悄话
Search "Excel Event Handler" 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: 解救美丽的公主的难题
2007: 高科技公司面试 q No.1解
2006: 童年回忆(矿石收音机)