vba如何同时触发多个目标值

How to trigger more than one target value simultaneously in vba

我有一个由用户在 K 列和 P 列中输入触发的代码: 如果在“K”中插入任何值,则偏移到 R 列中的相应单元格并填充用户名。 如果在“P”中插入任何值,则偏移到 Q 列中的相应单元格并使用 TODAY() 填充数据。

我的代码如下:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim UserName As String
UserName = Environ("username")

    If Target.Column <> 11 Then Exit Sub
    Target.Offset(, 7).Value = IIf(Target.Value = "", "", UserName)
   
    If Target.Column <> 16 Then Exit Sub
    Target.Offset(, 1).Value = IIf(Target.Value = "", "", Now)


End Sub

问题是它只适用于第一个 IF,我怎样才能让它同时适用于两个?

提前致谢!!

测试目标范围内的每个单元格。

Private Sub Worksheet_Change(ByVal Target As Range)

    Dim cell As Range
    
    Application.EnableEvents = False
    For Each cell In Target.Cells
        If cell.Column = 11 Then
            cell.Offset(, 7).Value = IIf(cell.Value = "", "", Environ("username"))
        ElseIf cell.Column = 16 Then
            cell.Offset(, 1).Value = IIf(cell.Value = "", "", Now)
        End If
    Next
    Application.EnableEvents = True

End Sub