VBA Excel编号格式问题

时间:2015-02-16 22:05:50

标签: excel vba excel-vba

我有一列约450,000个9位数字,用于确定另一列的输出。为什么进程会识别以数字3开头但不是0的九位数?

Sub Anything()

Dim rng As Range, cl As Range

Set rng = Range("Y2:Y" & Range("Y" & Rows.Count).End(xlUp).Row)

For Each cl In rng.Cells

    Dim outCell1 As Range
    Set outCell1 = cl.Offset(0, 54)


     Select Case Trim(cl.Value)

        Case "001019147"
            outCell1.Value = "thing1"

        Case "311019147"
            outCell1.Value = "thing2"

列中的所有单元格都包含9位数字,尽管列中大约有450,000个单元格,但只处理了大约2000个单元格。有什么输入吗?

2 个答案:

答案 0 :(得分:1)

对于select case声明,请尝试使用

Select Case Val(Trim(cl.Value))

    Case 1019147
        outCell1.Value = "thing1"

    Case 311019147
        outCell1.Value = "thing2"

这将允许您拥有值和/或多个值 e.g。

Case 1 to 22
Case 1,2,3,57,999
Case 1 to 8,300,400 to 499

答案 1 :(得分:0)

考虑:

选择案例修剪(cl.Text)