Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel VBA:根据下拉列表的值高亮显示/更改某些单元格的颜色(非条件格式)_Excel_Vba_If Statement - Fatal编程技术网

Excel VBA:根据下拉列表的值高亮显示/更改某些单元格的颜色(非条件格式)

Excel VBA:根据下拉列表的值高亮显示/更改某些单元格的颜色(非条件格式),excel,vba,if-statement,Excel,Vba,If Statement,我希望在单元格L10和L12中创建一个带有一些下拉选项的表单。根据这些单元格的值,我会突出显示某些单元格,以帮助用户知道哪些字段是必须填写的。这将是Excel 2003,所以我不能使用条件格式,因为只有3个,所以它需要在VBA中 我遇到了一个绊脚石,可能想得太多了,但有人能帮我吗 要求如下: If L10 = yes Then L12 = yellow If L12 = yes OR no OR maybe Then L16, L18, L20, L24, L26 = yellow If L

我希望在单元格L10和L12中创建一个带有一些下拉选项的表单。根据这些单元格的值,我会突出显示某些单元格,以帮助用户知道哪些字段是必须填写的。这将是Excel 2003,所以我不能使用条件格式,因为只有3个,所以它需要在VBA中

我遇到了一个绊脚石,可能想得太多了,但有人能帮我吗

要求如下:

If L10 = yes
Then L12 = yellow

If L12 = yes OR no OR maybe
Then L16, L18, L20, L24, L26 = yellow

If L12 = progress
Then L14, L16, L18, L20, L24, L26 = yellow

If L12 = fail
Then L16, L18 = yellow

If L12 = assess
Then L14, L16, L18, L20, L24, L26 = yellow

If L10 = no
Then L16, L18, L20, L24, L26 = yellow

在VBA编辑器中,选择您的工作表,然后在
工作表\u Change
子部分中,添加以下代码(以屏幕打印为例。同时确保您选择了正在使用的工作表):

现在,在
模块中添加以下子模块:

Sub SetCellColour(ByVal oTarget As Range)
    Dim oW As Worksheet: Set oW = ThisWorkbook.Worksheets("Sheet8")     ' Change the sheet name

    Select Case oTarget.Address
        Case "$L$10"
            Select Case LCase(Trim(oTarget.Value))
                Case "yes"
                    oW.Range("L12").Interior.Color = 65535
                Case Is = "no"
                    oW.Range("L16, L18, L20, L24, L26").Interior.Color = 65535
            End Select
        Case "$L$12"
            Select Case LCase(Trim(oTarget.Value))
                Case "yes", "no", "maybe"
                    oW.Range("L16, L18, L20, L24, L26").Interior.Color = 65535
                Case "progress", "assess"
                    oW.Range("L14, L16, L18, L20, L24, L26").Interior.Color = 65535
                Case "fail"
                    oW.Range("L16, L18").Interior.Color = 65535
            End Select
    End Select

End Sub

绝对完美的朋友。对此我感激不尽!不用担心,很高兴能帮上忙
Sub SetCellColour(ByVal oTarget As Range)
    Dim oW As Worksheet: Set oW = ThisWorkbook.Worksheets("Sheet8")     ' Change the sheet name

    Select Case oTarget.Address
        Case "$L$10"
            Select Case LCase(Trim(oTarget.Value))
                Case "yes"
                    oW.Range("L12").Interior.Color = 65535
                Case Is = "no"
                    oW.Range("L16, L18, L20, L24, L26").Interior.Color = 65535
            End Select
        Case "$L$12"
            Select Case LCase(Trim(oTarget.Value))
                Case "yes", "no", "maybe"
                    oW.Range("L16, L18, L20, L24, L26").Interior.Color = 65535
                Case "progress", "assess"
                    oW.Range("L14, L16, L18, L20, L24, L26").Interior.Color = 65535
                Case "fail"
                    oW.Range("L16, L18").Interior.Color = 65535
            End Select
    End Select

End Sub