数组元素到数字

时间:2015-02-21 17:35:14

标签: vba excel-vba excel

我有一个包含整数的数组。我想将每个数组元素分成数字,所以我可以为每个数字设置条件。我怎么能做这种分离?

Sub numberstodigits()
    Dim myArray
    myArray = Array(586, 453, 123, 456)
    '~~> ex.: 586 should be separated to 5, 8, 6
End Sub

2 个答案:

答案 0 :(得分:2)

考虑:

Sub numberstodigits()
    Dim myArray, digits As String
    myArray = Array(586, 453, 123, 456)
    digits = ""
    For Each a In myArray
        For i = 1 To Len(a)
            digits = digits & "," & Mid(a, i, 1)
        Next i
    Next a
    digits = Mid(digits, 2)
    MsgBox digits
End Sub

答案 1 :(得分:1)

另一种方法:

Sub M_snb()
  For Each it In Array(586, 453, 123, 456)
   sn = Split(StrConv(it, 64), Chr(0))
'  MsgBox Join(sn, vbLf)
  Next
End Sub