我想使用if条件来执行ClearContents任务。请找到我下面的代码。我写了下面的 2 个代码,但都没有成功。
第一次尝试
t = 1
Do While Cells(t, 1) <> ""
If Cells(t, 1) <> "=" Then
Cells(t, 1).ClearContents
End If
t = t + 1
Loop
Run Code Online (Sandbox Code Playgroud)第二次尝试
t = 1
Do While Cells(t, 1) <> ""
If Cells(t, 1) <> Formula Then
Cells(t, 1).ClearContents
End If
t = t + 1
Loop
Run Code Online (Sandbox Code Playgroud)基本上,我不想删除包含公式可用的单元格,但我想删除其他数据。
写这样的东西:
If Not Cells(t,1).HasFormula Then
End if
Run Code Online (Sandbox Code Playgroud)
它会起作用的。或者尝试这样:
Sub TestMe()
If Not Cells(1, 1).HasFormula Then
Debug.Print "No Formula"
Else
Debug.Print "Has Formula"
End If
End Sub
Run Code Online (Sandbox Code Playgroud)
以下是有关该房产的更多信息.HasFormula:
https://msdn.microsoft.com/en-us/library/office/ff837123.aspx
| 归档时间: |
|
| 查看次数: |
3057 次 |
| 最近记录: |