问题描述
我创建了一个宏,该宏将基于下拉选择填充电子表格中的多个字段,例如:
I created a macro that will populate multiple fields in a spreadsheet based on a drop-down selection, for example:
在L列中,有一个下拉列表,其中包含两个项目:是"和否".选择一个项目后,相邻的两个单元格将填充预定的数据,例如:
In column L, I have a drop down list of two items, "YES" and "NO". When an item is selected, the adjacent two cells will populate with predetermined data, for example:
选择是"将用黄色填充相邻的两个单元格
Selecting "YES" will fill the two adjacent cells with yellow
选择否"将使用单词"NULL"填充两个相邻的单元格
Selecting "NO" will populate the two adjacent cells with the word, "NULL"
这是我被困住的地方.
当某人在是"的相邻两个单元格中输入数据时,我需要用黄色填充物来消失.
When someone enters data in the adjacent two cells of "YES", I need the yellow fill to go away.
当有人向此类单元格中输入数据时,是否可以删除黄色填充?
Is there a way to remove the yellow fill when someone enters data into such cells?
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Application.ScreenUpdating = False
Select Case Target
Case "YES"
If Target = "YES" Then
Target.Offset(0, 1).Interior.ColorIndex = 6
Target.Offset(0, 2).Interior.ColorIndex = 6
If Not Target.Cells.Count = 1 Then
Exit Sub
If Intersect(Target, Columns(2)) Is Nothing Then
Exit Sub
End If
End If
End If
Case Else
If Target = "NO" Then
Target.Offset(0, 1) = "NULL"
Target.Offset(0, 2) = "NULL"
If Not Target.Cells.Count = 1 Then
Exit Sub
If Intersect(Target, Columns(2)) Is Nothing Then
Exit Sub
If Intersect(Target, Columns(2)) Is Nothing Then
Exit Sub
End If
End If
End If
End If
End Select
End Sub
推荐答案
尝试:
If Target = "NO" Then
Target.Offset(0, 1) = "NULL"
Target.Offset(0, 1).Interior.ColorIndex = xlColorIndexNone
Target.Offset(0, 2) = "NULL"
Target.Offset(0, 2).Interior.ColorIndex = xlColorIndexNone
这篇关于当数据从相邻的下拉列表中的单元格中输入时,如何删除填充色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!