如果单元格包含短语“01.01.1970 01:00:00”,我想用vba删除单元格的值
之后细胞应该是空的。
此日期仅在C列中,可以存在多行
工作表有很多行,日期不同
我只找到方法,如何删除整个行或列,如果单元格包含特定短语,但我只想删除单元格值。
有人可以帮助我吗?
答案 0 :(得分:0)
查看Range.Replace method。您需要将要检查的单元格本地化为C列。
with activesheet '<-set this worksheet reference properly!
.columns(3).replace what:="01.01.1970 01:00:00", _
replacement:=vbnullstring, lookat:=xlwhole
end with
答案 1 :(得分:0)
试试这个:(未经测试)
Dim RowCount as integer, i as integer
RowCount = Range("C" & .Rows.Count).End(xlUp).Row
For i = 1 to RowCount
If Range("C" & i).Value = "01.01.1970 01:00:00" Then
Range("C" & i).ClearContents
End If
Next i
答案 2 :(得分:0)
我找到了使用以下代码的解决方案/解决方法
'START: CONVERT UNIX TIMECODE
Range("D1").EntireColumn.Insert
lastRow = Range("C" & Rows.Count).End(xlUp).Row
Range("D2").Formula = "=(C2/86400)+25569+(+1/24)"
Range("D2").AutoFill Destination:=Range("D2:D" & lastRow)
Columns("D").NumberFormat = "DD.MM.YYYY HH:MM:SS"
Columns("D").Copy
Columns("D").PasteSpecial xlPasteValues
Columns("C").Delete
Range("C1").Value = "'Druckbeginn"
'END: CONVERT UNIX TIMECODE
'START: CHANGE FORMAT OF COLUMN D TO TEXT
Columns("C").NumberFormat = "@"
'END: CHANGE FORMAT OF COLUMN D TO TEXT
'START: DELETE SPECIFIC TEXT, THE NUMBER 25569.* IS FOR THE DATE AND EACH TIME FROM 01.01.1970
Columns("C").Replace "25569.*", "", xlPart
'END: DELETE SPECIFIC TEXT
'START: CHANGE FORMAT OF COLUMN D TO DATE AND TIME
Columns("C").NumberFormat = "DD.MM.YYYY HH:MM:SS"
'END: CHANGE FORMAT OF COLUMN D TO TEXT