Excel里的一个问题!求高人来帮忙!(好象涉及到编程的知识)

来源:百度知道 编辑:UC知道 时间:2024/06/13 14:05:32
我想在Excel 里面要求某个区域内的框框!
到了下个月 自动变成红色!

先在SHEET1的A1插入日期.我假设你的区域在A2:B3(如果不是,你可以在第三行代码中,自选更换)
然后按下ALT+F11,选择左边框中的THISWORKBOOK,点开
复制下列代码,以后每次打开工作簿时,都会对当前日期与A1判断,如果是A1的下个月,这个区域的边框就会变成红色.
Private Sub Workbook_Open()
Sheets("SHEET1").Select
Range("A2:B3").Select
Dim A
A = WorksheetFunction.Text(Date - Cells(1, 1), "MM")
If A = 1 Then
With Selection.Borders(xlEdgeLeft)
.ColorIndex = 3
End With
With Selection.Borders(xlEdgeTop)
.ColorIndex = 3
End With
With Selection.Borders(xlEdgeBottom)
.ColorIndex = 3
End With
With Selection.Borders(xlEdgeRight)
.ColorIndex = 3
End With
With Selection.Borders(xlInsideVertical)
.ColorIndex = 3
End With
With Selection.Borders(xlInsideHorizontal)
.ColorIndex = 3
End With
End If
End Sub

用条件格式即可,如,B1是日期,在要变成红色的区域用菜单->格式->条件格式