Split string in array not in cell range vba

2019-09-25 03:31发布

I am just new in creating macro and I have a macro that my colleague created which we used in our work . Now she is working with us and I need to do some changes.

Is it possible to get part of string in a string from other range to other cells? IS there's any code available for this? I think I need to split the data I need from column G to have the right result for column H and I. If there's any good help thank you in Advance. example:

column G

SD230X200X45/20

SD5000X2000X40/25

column H

20 <--(string get from G)

25 <--(string get from G)

column I

200 <--(string get from G)

2000 <--(string get from G)

1条回答
萌系小妹纸
2楼-- · 2019-09-25 04:08

Do like this.

Sub test()
    Dim vDB, vR()
    Dim i As Long, n As Long
    Dim s As String
    vDB = Range("g1", Range("g" & Rows.Count).End(xlUp))
    n = UBound(vDB, 1)
    ReDim vR(1 To n, 1 To 2)

    For i = 1 To n
        s = vDB(i, 1)
        vR(i, 1) = Split(s, "/")(1)
        vR(i, 2) = Split(s, "X")(1)
    Next i
    Range("h1").Resize(n, 2) = vR

End Sub
查看更多
登录 后发表回答