如何根據條件自動填入儲存格?

如何根據條件自動填入儲存格?

我需要根據 2 個單元格是否包含特定值自動填充單元格,然後自動運行它。這是我到目前為止所擁有的:

Private Sub Worksheet_Change(ByVal Target As Range)
     If target.Cells(5, "B").Value = "Secured" And target.Cells(6, "B").Value = "Amendment" Then
        Cells(10, "B") = "T2 - Medium Risk"
    End If

End Sub 

if 語句是,=IF(AND(D34="Secured",D35="Amendment"),"yes","")但「是」需要位於不同的儲存格中

答案1

這就是您要找的

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
     If Not Intersect(Target, Range("B5:B6")) Is Nothing Then
        If Cells(5, 2) = "Secured" And Cells(6, 2) = "Amendment" Then
            Cells(10, 2) = "T2 - Medium Risk"
        End If
    End If
End Sub

您希望它在更改發生在這兩個單元格內時觸發,並且如果它們匹配,則填充不同的單元格。如果你想刪除它,你也可以這樣做。

相關內容