[英]Clear contents of cell range with merged cells based on Interior.Color
[英]Conditionally clear contents of range of cells in a row based on cell value
我有一个包含两张纸的Excel文件:Sheet1和Sheet2。 工作表1具有商店信息,工作表2具有按商店信息的产品数量
在工作表1中,范围“ A1:A5”列出了5个商店名称,即商店A到商店E,而工作表1中的范围“ B1:B5”是一个下拉框,允许用户从以下选项中进行选择:“打开”,“已关闭”或“”。
在工作表2中,有一个表,按商店列出了产品数量。 就像是:
我正在寻找一种方法来清除Sheet1中相应存储区未设置为“打开”时Sheet2中范围B:F的内容。
当前,我正在将Sheet1的B列中的值链接到Sheet2的G列中,并在Sheet2中将代码设置为以下代码:
Private Sub Worksheet_Activate()
If Range("G2") <> "Open" Then
Range("B2:F2").ClearContents
End If
我该如何在循环中执行此操作,而不是分别复制此代码五次?
像这样吗
For i = 2 To 6 'This is the starting row (2) to the ending row (6)
If Range("G" & i) <> "Open" Then 'We use i to dynamically build the range as a string
Range("B" & i & ":F" & i).ClearContents
End If
Next i
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.