[英]Updating a range of cells based on the value of another cell
我非常新,所以請耐心等待。 我想評估C5:BM5范圍內的每個細胞。 如果該范圍中的任何單元格=“HOLIDAY”或“SUN”,則需要清除該列中的第7-19行。 我拼湊了下面的代碼,它做了我需要的,它只是非常緩慢。 我知道必須有更好的方法。 尋找一些聰明的建議。
Sub HolidayUpdate()
Dim Cell As Range
For Each Cell In Sheets("Production Calendar").Range("C5:BM5")
If Cell = "HOLIDAY" Then
Cell.Offset(2, 0).ClearContents
Cell.Offset(3, 0).ClearContents
Cell.Offset(4, 0).ClearContents
Cell.Offset(5, 0).ClearContents
Cell.Offset(6, 0).ClearContents
Cell.Offset(7, 0).ClearContents
Cell.Offset(8, 0).ClearContents
Cell.Offset(9, 0).ClearContents
Cell.Offset(10, 0).ClearContents
Cell.Offset(11, 0).ClearContents
Cell.Offset(12, 0).ClearContents
Cell.Offset(13, 0).ClearContents
Cell.Offset(14, 0).ClearContents
ElseIf Cell = "SUN" Then
Cell.Offset(2, 0).ClearContents
Cell.Offset(3, 0).ClearContents
Cell.Offset(4, 0).ClearContents
Cell.Offset(5, 0).ClearContents
Cell.Offset(6, 0).ClearContents
Cell.Offset(7, 0).ClearContents
Cell.Offset(8, 0).ClearContents
Cell.Offset(9, 0).ClearContents
Cell.Offset(10, 0).ClearContents
Cell.Offset(11, 0).ClearContents
Cell.Offset(12, 0).ClearContents
Cell.Offset(13, 0).ClearContents
Cell.Offset(14, 0).ClearContents
End If
Next Cell
End Sub
這是您的代碼的更新。
Sub HolidayUpdate() Dim rgCell As Range application.screenupdating=false application.calculation=xlcalculationmanual For Each rgCell In Sheets("Production Calendar").Range("C5:BM5") If rgCell = "HOLIDAY" OR rgCell = "SUN" _ Then rgCell.Offset(2, 0).resize(13).ClearContents Next rgCell application.screenupdating=true application.calculation=xlCalculationAutomatic End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.