将存储为文本的数字转换为数字? [英] Convert numbers stored as text to numbers?

查看:67
本文介绍了将存储为文本的数字转换为数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将存储为文本的数字转换为数字?

How can I convert numbers stored as text to numbers?

我尝试设置:

ActiveSheet.Range("H154").NumberFormat = "General"

但这不起作用!

我发现唯一可行的方法是使用文本到列"或单击单元格进行编辑,然后单击Enter.

The only things I've found that work are using "Text to columns" or clicking the cell to edit it and then clicking Enter.

但是我真的很想找到一种使用VBA将存储为文本的工作表中的数字单元转换为数字的方法.

But I would really like to find a way to turn number cells in a sheet stored as text into numbers using VBA.

推荐答案

一般技术是复制PasteSpecial,乘以1

在代码中,如下所示:

Sub ConvertToNumber()
    Dim rng As Range
    Dim cl As Range
    Dim rConst As Range

    ' pick an unused cell
    Set rConst = Cells(1, 4)
    rConst = 1

    Set rng = Cells.SpecialCells(xlCellTypeConstants)
    rng.NumberFormat = "General"
    rConst.Copy
    rng.PasteSpecial xlPasteValues, xlPasteSpecialOperationMultiply

    rConst.Clear
End Sub

这篇关于将存储为文本的数字转换为数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆