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