将字符串数据拆分为多列访问

时间:2017-07-25 19:35:09

标签: string vba ms-access access-vba

我有一个包含多个服务代码的列,我希望将其拆分为不同的列,以便在Access中进行计数。一行的示例如下所示:

$= ** ;= AA AC BB1 CA5 CC4 CC5 CC6 CC7 CC9 CD1 CI CR D0 D1 D2 D3 D9 F> F> FA7 FA9 FB1 HA6 KJ P* P? PW PZ QG V4 WJ 1D 2O

目标是创建一个AA列,一个AC列等,以计算哪些服务代码用于哪一行。此外,每一行服务代码都与其他服务代码完全不同。有什么想法吗?我也熟悉宏和SQL查询。

这是我到目前为止所拥有的:

Sub splitColumn()

Dim rst As DAO.Recordset
Dim arr() As String
Dim i As Integer

Set rst = CurrentDb.OpenRecordset("SELECT * FROM _Raw")
arr = split(rst("Serv Cde String"), ",")

For i = 0 To UBound(arr)
  '/do something here
Next i

End Sub

谢谢,

丽贝卡

1 个答案:

答案 0 :(得分:0)

分隔符似乎错了:

Sub splitColumn()

    Dim rst As DAO.Recordset
    Dim arr As Variant
    Dim i As Integer

    Set rst = CurrentDb.OpenRecordset("SELECT * FROM _Raw")
    arr = Split(rst("Serv Cde String").Value, " ")

    For i = LBound(arr) To UBound(arr)
      '/do something here
      Debug.Print i, arr(i)
    Next

    Set rst = Nothing

End Sub