我可以告诉Excel VBA在我的代码中搜索一个句子吗?

时间:2019-03-09 11:21:03

标签: excel vba

我在代码中犯了一个错误,我写了.FormulaR1C1 = ""而不是.Value = 0。 我在代码中写了很多错误,我想修复它。 有没有办法告诉excel,无论他在哪里找到组合.value = 0并将其更改为.FormulaR1C1 = ""? 如果没有,是否有办法搜索组合.value = 0,所以我可以手动更改它?

1 个答案:

答案 0 :(得分:0)

Yoni,如上所述,您需要将 0 替换为空字符串...

Sub AdjustZeroCells()

Dim ws As Worksheet
Dim cell As Range

'sets worksheet variable
Set ws = ThisWorkbook.Worksheets("Sheet1")

'only loops through cells with formulas
For Each cell In ws.UsedRange.SpecialCells(xlCellTypeFormulas)
    If cell.Value = 0 Then: cell.Value = ""
Next cell

'cleanup
Set cell = Nothing: Set ws = Nothing

End Sub

丹尼, ExcelVBADude