这是一个有趣的问题,我得到了下面的代码使用在B列的单元格设置验证方法时,列A
B列中的文本的颜色输入了二维码工作在选择选项后变为蓝色,但您想要的绿色和红色文本并不是真的可行,因为在单元格内下拉列表中总是显示黑色,而不管单元格的字体颜色如何。
该代码并不完美,但更多的只是一个概念证明和一些让你大开局的东西。
Dim CHANGING_VAL As Boolean 'Global Variable that can be set to prevent the onchange being fired when the Macro is removing the description from the dropdown.
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Column = 2 And CHANGING_VAL = False Then
CHANGING_VAL = True
If InStr(1, Target.Value, "~") > 2 Then
Target.Value = Left(Target.Value, InStr(1, Target.Value, "~") - 2)
End If
Target.Validation.Delete
Target.Font.Color = RGB(0, 0, 255)
CHANGING_VAL = False
End If
End Sub
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Column = 2 Then
If Target.Offset(0, -1) <> "" Then
strValidList = ""
For intRow = 1 To 300
If Sheets("Data").Cells(intRow, 1) = Target.Offset(0, -1) Then
If Sheets(Target.Parent.Name).Cells(3, 4) = "English" Then
strValidList = strValidList & Sheets("Data").Cells(intRow, 2) & " ~ " & Sheets("Data").Cells(intRow, 3) & ", "
Else
strValidList = strValidList & Sheets("Data").Cells(intRow, 2) & " ~ " & Sheets("Data").Cells(intRow, 4) & ", "
End If
End If
Next
If strValidList <> "" Then
strValidList = Left(strValidList, Len(strValidList) - 2)
Target.Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=strValidList
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End If
End If
Else
Sheets(Target.Parent.Name).Range("B:B").Validation.Delete
End If
End Sub
只能我使用验证所以你可能使用VBA来设置每个电池所需的验证生成的细胞内apprear一旦你进入A列中的值,或者您可以使用表格的下拉式选单,包含一个下拉列表,当列A中的值被输入时弹出。您需要遍历表单数据以提取零件。 – Gordon