本文介绍了将单元格值拆分为数字数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含"12_34_56"之类的单元格

I have a cell containing something like "12_34_56"

我用过:

MyNumbers = Split(Cells(1, 1).Value, "_")

将数值拆分为一个数组,但结果是一个字符串数组!

to split the numeric values into an array , but the result is an array of strings!

我知道我可以在数组的每个值上使用CInt,但是无法直接获取数字数组吗?

I know that I can use CInt on every value of the array but isn't any way to obtain a numeric array directly?

预先感谢

推荐答案

这对我来说非常有效,并且设置起来非常简单!我将以单元格A1为例,并使用数字字符串.

This worked great for me and was very easy to set up! I will use cell A1 as the example with the string of numbers.

Dim strarray as Variant
Dim intarray as Variant
Dim x as Long

strarray = Split(Range("A1").Value, "_")
ReDim intarray(LBound(strarray) to UBound(strarray))
For x = LBound(strarray) To UBound(strarray)
    intarray(x) = CInt(strarray(x))
Next x

这篇关于将单元格值拆分为数字数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 12:29