这是我的代码:
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("A1").Value = "ORACLE" Then
Range("B1").Value = "DATABASE"
ElseIf Range("A1").Value = "UNIX" Then
Range("B1").Value = "SERVER"
End If
End Sub
如何为整个列执行此操作?
答案 0 :(得分:0)
试试这个:
Private Sub Worksheet_Change()
Dim rng As Range
Range("A1").Select
For Each rng In Range("A:A")
If rng.Value = "ORACLE" Then
ActiveCell.Offset(0, 1).Value = "DATABASE"
ActiveCell.Offset(1, 0).Select
ElseIf rng.Value = "UNIX" Then
ActiveCell.Offset(0, 1).Value = "SERVER"
ActiveCell.Offset(1, 0).Select
End If
Next rng
End Sub
答案 1 :(得分:0)
这不依赖于activecell,因为它基于A列中的事件,如果A列发生变化,它只会更改B列中的单元格。
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("A:A")) Then
If Target.value = "ORACLE" Then
Range("B" & Target.Row).value = "DATABASE"
ElseIf Target.value = "UNIX" Then
Range("B" & Target.Row).value = "SERVER"
End If
End If
End Sub