我最近遇到以下问题。对于大多数文件,下面的代码可以正确确定空单元格并将其删除,但是对于某些行,这些单元格以文本日期显示。例如,2019年5月28日,该函数不会删除任何内容。我该如何解决这个问题?
Set sht1 = DestWbk.Sheets("sheet1")
check="sample1"
Set f = sht1.Cells.Find(What:=check, LookIn:=xlValues)
If Not f Is Nothing Then
Set column_range = sht1.UsedRange.Columns(f.Column)
On Error Resume Next 'ignore error if no blanks
column_range.SpecialCells(xlCellTypeBlanks).EntireRow.Delete
On Error GoTo 0 'stop ignoring errors
End If
End Sub
有关该问题的更多信息:如果我手动单击空白行并清除所有内容,然后运行脚本-它可以正常工作。但是,我也检查了countblanks,它正确地计数了空白单元格。怎么可能?
1)Select the entire column and find and replace
2)Leave find as empty, replace with @
3)Replace @ with empty, run the script.
我实际上不知道怎么可能,但是以某种方式从另一个文件复制并造成此类问题。