我有一个BOM的Excel电子表格,我正在尝试有条件地格式化。布置数据使得列A是项目编号。由于BOM具有交替,因此存在重复的数字。我想浏览电子表格,对于每个项目编号,在F列中找到带有“活动”的项目并将其突出显示为绿色并隐藏其他行上的替换项。如果没有“活动”项目,我想将项目突出显示为黄色并保持显示。我有当前的vba脚本,它突出显示。如果您查看示例数据,我基本上希望每个项目编号都有一行显示活动部件,但如果没有活动部件,则显示黄色的历史或停产部件
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim icolor As Integer
Dim lastrow As Long
Dim i As Integer
Dim cell As Range
Dim sheetname As String
sheetname = Application.ActiveSheet.Name
With Worksheets(sheetname)
lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
Application.ScreenUpdating = False
For Each cell In Range("F1:F" & lastrow)
Select Case cell.Value
Case Is = "Active"
cell.EntireRow.Interior.ColorIndex = 10
Case Is = "Status"
cell.EntireRow.Interior.ColorIndex = 15
Case Is = ""
cell.EntireRow.Interior.ColorIndex = 2
cell.EntireRow.Hidden = True
Case Else
cell.EntireRow.Interior.ColorIndex = 6
End Select
Next cell
Application.ScreenUpdating = True
End Sub
答案 0 :(得分:1)
您需要将行高设置为零以隐藏它
cell.EntireRow.RowHeight = 0
但别忘了在其他两种情况下重置它
cell.EntireRow.AutoFit
答案 1 :(得分:0)
请检查单元格值是否为NULL以及“”