2017教育部教学评估:求助:excel的函数

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/04 20:03:21
各位高手,请帮忙编一个公式
在excel中如果在单元格A1中输入字母A,单元格C1就变成红色,而在单元格A1中输入字母B,单元格D1就变成红色,而在单元格A1中输入字母C,单元格E1就变成红色,请那位高手帮帮我,谢谢了

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ErrorHandle

With Target
Select Case .Cells(1, 1).Value
Case "A"
.Cells(1, 3).Interior.ColorIndex = 3
.Cells(1, 3).Interior.Pattern = xlSolid
.Cells(1, 4).Interior.ColorIndex = xlNone
.Cells(1, 5).Interior.ColorIndex = xlNone
Exit Sub
Case "B"
.Cells(1, 4).Interior.ColorIndex = 3
.Cells(1, 4).Interior.Pattern = xlSolid
.Cells(1, 3).Interior.ColorIndex = xlNone
.Cells(1, 5).Interior.ColorIndex = xlNone
Exit Sub
Case "C"
.Cells(1, 5).Interior.ColorIndex = 3
.Cells(1, 5).Interior.Pattern = xlSolid
.Cells(1, 3).Interior.ColorIndex = xlNone
.Cells(1, 4).Interior.ColorIndex = xlNone
Exit Sub
Case Else
.Cells(1, 3).Interior.ColorIndex = xlNone
.Cells(1, 4).Interior.ColorIndex = xlNone
.Cells(1, 5).Interior.ColorIndex = xlNone
Exit Sub

End Select
End With

ErrorHandle:
If Err.Number <> 0 Then
MsgBox "Err.Number " & Err.Number & ": " & Err.Description, vbInformation, "Error Message"
End If
End Sub

那要编程才行的
可以启用宏

很简单!用条件格式就可以解决了,不要用什么宏,很麻烦!