VBA-Excel文本到数字格式问题-用错误的值覆盖

时间:2019-07-17 15:43:42

标签: excel vba

我有一个代码,可将选定单元格中的文本字符串转换为值。效果很好,直到Selection中有一些隐藏的行。然后,隐藏行下方的值将被上方单元格中的值覆盖。

您对如何修复以下代码有任何想法吗?

Sub text_to_values()

With Application
    .ScreenUpdating = False
    .EnableEvents = False
    .Calculation = xlCalculationManual
End With

With Selection.SpecialCells(xlCellTypeVisible)
    .NumberFormat = "General"
    .Value = .Value
End With

With Application
    .ScreenUpdating = True
    .EnableEvents = True
    .Calculation = xlCalculationAutomatic
End With

Selection.NumberFormat = "0"

End Sub

1 个答案:

答案 0 :(得分:1)

替换为此...

For each cll in Selection.SpecialCells(xlCellTypeVisible)
    cll.NumberFormat = “General”
    cll.Value = cll.Value
Next cll