在从相邻下拉列表的单元格中输入数据时,如何删除填充颜色?

时间:2017-09-05 17:50:17

标签: excel vba excel-vba

我创建了一个宏,它将根据下拉选项填充电子表格中的多个字段,例如:

在L栏中,我有两个项目的下拉列表," YES"并且"否"。选择项目时,相邻的两个单元格将填充预定数据,例如:

选择"是"将用黄色填充两个相邻的单元格

选择"否"将使用单词" NULL"

填充两个相邻单元格

这里是我被困的地方..

当有人在" YES"的相邻两个单元格中输入数据时,我需要黄色填充消失。

当有人将数据输入此类单元格时,有没有办法删除黄色填充?

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

Application.ScreenUpdating = False

Select Case Target

Case "YES"
    If Target = "YES" Then
        Target.Offset(0, 1).Interior.ColorIndex = 6
        Target.Offset(0, 2).Interior.ColorIndex = 6
            If Not Target.Cells.Count = 1 Then
                Exit Sub
                    If Intersect(Target, Columns(2)) Is Nothing Then
                        Exit Sub
                    End If
            End If
    End If
Case Else
    If Target = "NO" Then
        Target.Offset(0, 1) = "NULL"
        Target.Offset(0, 2) = "NULL"
            If Not Target.Cells.Count = 1 Then
                Exit Sub
                    If Intersect(Target, Columns(2)) Is Nothing Then
                        Exit Sub
                            If Intersect(Target, Columns(2)) Is Nothing Then
                                Exit Sub
                            End If
                    End If
            End If
    End If
End Select
End Sub

1 个答案:

答案 0 :(得分:0)

尝试:

 If Target = "NO" Then
    Target.Offset(0, 1) = "NULL"
    Target.Offset(0, 1).Interior.ColorIndex = xlColorIndexNone
    Target.Offset(0, 2) = "NULL"
    Target.Offset(0, 2).Interior.ColorIndex = xlColorIndexNone