|
楼主 |
发表于 2016-2-22 13:52
|
显示全部楼层
问题:如何高亮显示本周输入数据?
第一步 手工为本工作簿创建一个名称“日期”。
第二步 按Alt+F11打开代码编辑器,在ThisWorkbook模块中编写代码:
- <P>Private Sub Workbook_Open() '打开工作簿时,系统自动运行下面的程序
- Dim Sh As Worksheet
- Dim Rng As Range
- Application.ScreenUpdating = False
- If [日期] <> Date Then '检查保存的日期[日期]是否与当前系统日期相等,如果不是,运行下面一段程序
- For Each Sh In Worksheets '遍历各个工作表
- For Each Rng In Sh.UsedRange '遍历工作表中各单元格
- If Rng.Interior.Color = 2815 Or Rng.Interior.Color = 65534 Then Rng.Interior.Pattern = 0 '清除颜色
- Next
- Next
- End If
- ThisWorkbook.Names("日期").RefersTo = Date
- Application.ScreenUpdating = True
-
- End Sub 'Open 事件程序至此结束</P>
- <P>Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range) '编辑单元格,将运行下面的程序
- Dim Rng As Range
- Application.ScreenUpdating = False
- For Each Rng In Target
- If Rng.Formula = "" Then '如果单元格为空,则
- Rng.Interior.Pattern = 0 '清除填充格式
- Else
- Rng.Interior.Color = IIf(Rng.HasFormula, 65534, 2815) '给单元格着色
- End If
- Next
- Application.ScreenUpdating = True
- End Sub</P>
复制代码
|
|