在一个范围(I3:CD161)中,我有重复的4列标题:(项目名称,成本,零售,销售日期)。每次在“售出日期”列中出现日期条目时,我需要通过每一套清除所有4个连续单元格的内容(在“项目名称”,“成本”,“零售”,“销售日期”下) 。我试图在这里附上一个屏幕截图,但它不允许。所以,我放了一个链接。请看下面的内容。
在屏幕截图中,请注意红色单元格颜色和删除线来自条件格式。这意味着我通过颜色找到细胞然后清除内容太复杂了。这就是为什么我宁愿搜索每个“已售出日期”列>找到包含日期条目的所有单元格>向左偏移3个以上的单元格>清除这4个相邻细胞的内容(包括日期)>通过所有范围(I3:CD161)。我希望这是有道理的。
非常感谢您的帮助。
答案 0 :(得分:0)
经过测试的工作解决方案,用于查找特定日期并清除其左侧(包括其自身)三个,两个和一个单元格的内容。将循环整张表格进行检查。
Sub TestIt()
Dim Rng As Range, DateToFind As Date
DateToFind = InputBox("Enter the date to find", "Enter Date", "mm/dd/yyy")
Do
Set Rng = Cells.Find(DateToFind, LookIn:=xlFormulas, LookAt:=xlWhole)
If Not Rng Is Nothing Then Range(Rng.Offset(0, -3), Rng).ClearContents
Loop Until Rng Is Nothing
End Sub
答案 1 :(得分:0)
这将搜索整整一年:
Sub TestIt()
Dim Rng As Range, YearToFind As Integer
YearToFind = InputBox("Enter the year to find", "Enter Year", "yyyy")
For Each Rng in ActiveSheet.Cells 'I'd recommend making this search range smaller as Cells searches whole sheet
If Year(Rng.Value) = YearToFind Then Range(Rng.Offset(0, -3), Rng).ClearContents
Next Rng
End Sub