我想使用if
条件执行ClearContents
任务。请找到我下面的代码相同。我写了下面的两个代码,但都没有成功。
第一次尝试
t = 1
Do While Cells(t, 1) <> ""
If Cells(t, 1) <> "=" Then
Cells(t, 1).ClearContents
End If
t = t + 1
Loop
第二次尝试
t = 1
Do While Cells(t, 1) <> ""
If Cells(t, 1) <> Formula Then
Cells(t, 1).ClearContents
End If
t = t + 1
Loop
基本上,我不想删除包含公式可用的单元格,但我想删除其他数据。
这样写:
If Not Cells(t,1).HasFormula Then
End if
会的。或尝试这样:
Sub TestMe()
If Not Cells(1, 1).HasFormula Then
Debug.Print "No Formula"
Else
Debug.Print "Has Formula"
End If
End Sub
这是有关该.HasFormula
属性的更多信息:
https://msdn.microsoft.com/zh-CN/library/office/ff837123.aspx
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句