Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.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 - Fatal编程技术网

Excel VBA添加数据验证对两个单独单元格进行倒圆着色

Excel VBA添加数据验证对两个单独单元格进行倒圆着色,excel,vba,Excel,Vba,如果用户在工作表mySheet.Cells(第3行)更改数据验证。 要求是程序立即将相同的背景颜色更新到不同的表,如mySecondSheet.Cells(第2行)。 我必须在代码中添加什么 Public Function addDataValidation(row As Long) Dim optionList(2) As String optionList(0) = "1" optionList(1) = "2" optionList(2) = "3" With myShe

如果用户在工作表
mySheet.Cells(第3行)更改数据验证。

要求是程序立即将相同的背景颜色更新到不同的表,如
mySecondSheet.Cells(第2行)。

我必须在代码中添加什么

Public Function addDataValidation(row As Long)

Dim optionList(2) As String

optionList(0) = "1"
optionList(1) = "2"
optionList(2) = "3"

    With mySheet.Cells(row, 3).Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=Join(optionList, ",")
    End With

   With mySheet.Cells(row, 3).FormatConditions.Add(xlCellValue, xlEqual, "=1")
        .Font.Bold = True
        .Interior.ColorIndex = 4
        .StopIfTrue = False
    End With

    With mySheet.Cells(row, 3).FormatConditions.Add(xlCellValue, xlEqual, "=2")
        .Font.Bold = True
        .Interior.ColorIndex = 6
        .StopIfTrue = False
    End With

    With mySheet.Cells(row, 3).FormatConditions.Add(xlCellValue, xlEqual, "=3")
        .Font.Bold = True
        .Interior.ColorIndex = 3
        .StopIfTrue = False
    End With

    With mySheet.Cells(row, 3)
            .HorizontalAlignment = xlCenter
            .Value = optionList(0)
    End With

End Function