函数没错,但是函数不能用来执行把背景变为红色等过程,函数返回的只有值.
如果你要执行过程,需要另外编一个过程.不能放到这个函数里
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim lim As Integer
Dim bodyLen As Integer
Dim cell As Range
For Each cell In Range("1:1")
lim = Len(cell)
bodyLen = Len(cell.Offset(1, 0))
If bodyLen > lim Then
cell.Interior.ColorIndex = 36
Else
cell.Interior.ColorIndex = xlNone
End If
Next
End Sub
在工作表里面添加Selectiongchange事件