Home » excel » excel – VBA – Split & array

excel – VBA – Split & array

Posted by: admin May 14, 2020 Leave a comment


Thanks for your prompt help !!
Though i have managed to get rid of End IF issue, but now the cod ehas gone in infinite loop & never stops,

below are the 6 rows of the file i am working on, i have many more
column in the data, where the data will be replicated in new inserted
rows (except for the column i am working on, which will have the
delimited text)-

01/06/18 Sent IM% 02/06/18 Emailed CA% 05/06/18 Data room access provided to Ian% 12/06/18 Spoke to is overseas won’t be putting in an offer “call me after process”

01/11/17- Called Phil and sent IM. Greenstone act for a number of private Chinese developers.

02/11/17 Australian developer. Sent IM

02/11/17 Left voicemail . Chinese developer.

02/11/17 Sent IM and left message on his mobile. % 06/11/17 Followed up with call on his mobile.Left message.Hard to get hold of . % 06/11/17. Has now signed CA and downloaded various documents in the data room. % 13/11/17. Left message with Aidan this morning. % 14/11/17. Aidan called this afternoon top advise they have carefully considered and have run numbers but pricing will be too low for Panuku to consider.Major concerns with the site referred to as a ” perfect trifecta” Part of site is peat and requires more foundation work. High water table which requires additional work and extra foundations Contamination- Council is strict on this particularly for residential development./ Will require removal and refill to maintain height. All of the above is very costly and has impacted on their pricing which is around $300psm. Even at this level their profit margin is not high. If no success with tender they are happy to sit down and discuss with Panuku.

02/11/17 Spoke with Shen and resent IM. He will review.

The code i am using, as suggested by you is below :-

Dim r As Long, i As Long, ar As Variant
With Worksheet("Sheet1")

   For r = .Cells(.Rows.Count, "A").End(xlUp).Row To 2 Step -1
       ar = Split(.Cells(r, "A").Value, "%")
       If UBound(ar) >= 0 Then .Cells(r, "A").Value = ar(0)
       For i = UBound(ar) To 1 Step -1
           .Cells(r + 1, "A") = ar(i)
       Next i
   Next r
End With

Please suggest a solution to this,

thanks !!

How to&Answers:

The problem isn’t so much the arr variable as the way you’ve constructed your loop. It seems that you are trying to split all the cells in r at once.

Sub splitByColB()

    Dim r As long, i As Long, ar as variant

    with worksheets("sheet1")

        for r = .cells(.rows.count, "A").end(xlup).row to 2 step -1
            ar = Split(.cells(r, "A").Value, "%")
            If UBound(ar) >= 0 Then .cells(r, "A").Value = ar(0)
            For i = UBound(ar) To 1 Step -1
                .cells(r + 1, "A") = ar(i)
            Next i
        next r
    end with

End Sub

Just had another look at your code and it likely would work if you just set r to the last populated cell in column A instead of the range from A2 to the last populated cell.

Set r = Range("A" & plr)

No idea where plr comes from though.