Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
364 views
in Technique[技术] by (71.8m points)

excel - Split string in array not in cell range vba

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)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...