我对VBA很陌生,如果有人能帮助我会很棒。我被分配为我的工作创建一个新模板。问题是我找到了一个代码来创建一个弹出,高亮和更改B列中单元格的颜色,如果条件是fasle。我有他的代码为Just coloumn B工作,但现在是主要问题。如何为A,C,D等列实现相同的逻辑?
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cell As Excel.Range
If Not Intersect(Target, Columns("B")) Is Nothing Then
For Each cell In Intersect(Target, Columns("B"))
If Len(cell.Value) > 60 Then
cell.Font.ColorIndex = 1
cell.Interior.ColorIndex = 22
cell.Font.Bold = True
MsgBox "ID is exceeding the limit. Please check !!"
ElseIf Len(cell.Value2) <= 60 Then
cell.Font.ColorIndex = 1
cell.Interior.ColorIndex = 2
cell.Font.Bold = False
End If
Next cell
End If
End Sub
提前谢谢你:)
答案 0 :(得分:0)
您可以使用Range
而不是Columns
,例如Range("A1:F1000")
或者您需要去的地方。
答案 1 :(得分:0)
我想说在这种情况下重新创建相同的代码并编辑列值“B”。保存它们并创建一个链接到每个模块的按钮。
A列的按钮1 B栏的按钮2
等。