gpt4 book ai didi

VBA-根据单元格是否包含特定文本隐藏行

转载 作者:行者123 更新时间:2023-12-03 02:28:28 25 4
gpt4 key购买 nike

希望扫描整列,看看产品(在单个单元格中)是否可能停产。如果单元格中包含“中止”一词,则情况如此。如果停止,我希望隐藏整行。有什么建议吗?

Sub HideRows()
Dim c As Range
For Each c In Range("B3:B2452")
If InStr(1, c, "Discontinued") Or InStr(1, c, "discontinued") Then
c.EntireRow.Hidden = True
End If
Next
End Sub

最佳答案

Sub HideRows()

Dim rCheck As Range
Dim rHide As Range
Dim rCheckCell As Range

Set rCheck = ActiveWorkbook.ActiveSheet.Range("B3:B2452")
rCheck.EntireRow.Hidden = False

For Each rCheckCell In rCheck.Cells
If InStr(1, rCheckCell, "Discontinued", vbTextCompare) > 0 Then
If Not rHide Is Nothing Then Set rHide = Union(rHide, rCheckCell) Else Set rHide = rCheckCell
End If
Next rCheckCell

If Not rHide Is Nothing Then rHide.EntireRow.Hidden = True

End Sub

关于VBA-根据单元格是否包含特定文本隐藏行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45594700/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com