VBA:将文本转换为数字 [英] VBA: Convert Text to Number

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

问题描述

我有几列数字,无论出于何种原因,都被格式化为文本。这可以防止我使用诸如小计功能之类的算术函数。什么是将这些文本数字转换为真实数字的最佳方式?

以下是特定问题的屏幕截图:


我已经试过这些代码片段了:

  Columns(5).NumberFormat =0

  Selection.PasteSpecial粘贴:= xlPasteValues,操作:= xlNone,SkipBlanks _ 
:= False,Transpose:= False
[E:E]

解决方案 / code>到您需要的适当范围)来解决这个问题:

  [E:E]。选择
With Selection
.NumberFormat =General
.Value = .Value
End With


I have columns of numbers that, for whatever reason, are formatted as text. This prevents me from using arithmetic functions such as the subtotal function. What is the best way to convert these "text numbers" to true numbers?

Here is a screenshot of the specific issue:

I've tried these snippets to no avail:

Columns(5).NumberFormat = "0"

and

 Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False

解决方案

Use the below function (changing [E:E] to the appropriate range for your needs) to circumvent this issue:

[E:E].Select
With Selection
    .NumberFormat = "General"
    .Value = .Value
End With

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

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