這是一個有趣的問題,我得到了下面的代碼使用在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