在VBA中清除具有特定内容的单元格

我有一个Excel模型的数据输出。 这个模型把所有你想要的数据都吐出来,但是为了完成这个任务,它还会在每个单元格中放置一个“空格”字符,否则这个字符就是空白的。 – 我的意思是每个单元格都是XFD1048576。

我需要取这些数据的范围,并将它们转换成数据库格式,如果我可以清除任何单元格中的“空格”的内容,我相信我可以做到 – Range(Selection,Selection.End xlDown))。select – 将只select数据。

有没有简单的方法让VBAselect整个工作表,并清除具有特定内容的单元格的内容?

 Public Function Get_Last_Row_Find(ByVal rngToCheck As Range) As Long Dim rngLast As Range Set rngLast = rngToCheck.Find(what:="*", searchorder:=xlByRows, SearchDirection:=xlPrevious) If rngLast Is Nothing Then Get_Last_Row_Find = rngToCheck.Row Else Get_Last_Row_Find = rngLast.Row End If If Get_Last_Row_Find <= 1 Then Get_Last_Row_Find = 2 End If End Function Public Function Get_Last_Col_Find(ByVal rngToCheck As Range) As Long Dim rngLast As Range Set rngLast = rngToCheck.Find(what:="*", searchorder:=xlByColumns, SearchDirection:=xlPrevious) If rngLast Is Nothing Then Get_Last_Col_Find= rngToCheck.Column Else Get_Last_Col_Find = rngLast.Column End If If Get_Last_Col_Find<= 1 Then Get_Last_Col_Find= 2 End If End Function Sub Main x = Get_Last_Col_Find(Activesheet.Range("A1:XFD1") y = Get_Last_Row_Find(Activesheet.Range("A1:A999999") for i = 1 to x for j = 1 to y if Activesheet.Range("A1").Offset(i-1,j-1).Value = chr(32) then Activesheet.Range("A1").Offset(i-1,j-1).Value = "" endif next j next i end sub 

您也可以尝试添加: http : //www.microsoft.com/en-us/download/details.aspx?id=21649