数字文本格式

我有一张大桌子,每个单元格都是从macros观上填充的。 但我不想在单元格中的公式,我只想要数字,所以我转换每个单元格,如下所示:

Sub FormulaToNumber(sheetName As String, sheetRange As String) Dim sh As Worksheet, Cell As Range, Plage As Range Set sh = Worksheets(sheetName) sh.Select With sh Set Plage = .Range(sheetRange) For Each Cell In Plage Cell.Value = Format(Cell.Value, "0.00") Cell.NumberFormat = "0.00" Next End With Application.CutCopyMode = False End Sub 

它的作品,每个细胞现在是一个数字,而不是公式,但它是一个文本格式的数字,为什么? 我想使用cell.NumberFormat或plage.NumberFormat。 但它不起作用。 Excel不断告诉我这是文本格式。 而当我通过右键单击每个单元格,并: cell format/Number/Nombre is selectionned.

如果我点击resolv的问题,将文本的单元格转换为数字它的工作。 单元格现在是数字格式,文本在单元格右侧alignment,我的summ函数运行良好。

这是因为Format()使Text和TextText在inputTextText后不会将其转换为数字。

 Sub qwerty() Set Plage = Range("A1:A10") For Each Cell In Plage Cell.Value = Cell.Value Cell.NumberFormat = "0.00" Next End Sub 

不需要For循环:

 Sub MacroValues() Range("A1:A10").Copy Range("A1").PasteSpecial Paste:=xlPasteValues End Sub