shahin
Active Member
I've written a script in vba to get the last portion of a big string (separated by space). When I execute the script, it does it's job flawlessly by placing those scraped values in it's next column. However, when any blank cells come along it place those values in wrong position. How can I modify my script in such a way so that It will check first whether any cell is blank. If it finds any blank cell then it will skip that and look for the next cell with values and do the operation until the last row?
Script I'm trying with:
I tried with the below strings:
With my macro the result I'm having:
My expected output:
The leading numbers are the row number.
Script I'm trying with:
Code:
Sub splitting_Stringss()
Dim lrow As Long, cel As Range
Dim i As Long, item_list As Variant
lrow = Range("A" & Rows.Count).End(xlUp).Row
For Each cel In Range("A1:A" & lrow)
If InStr(1, cel.Value, " ") <> 0 Then
item_list = Split(cel, " ")
i = UBound(item_list)
r = r + 1: Cells(r, 2) = item_list(i)
End If
Next cel
End Sub
I tried with the below strings:
Code:
ColumnA
1 NACLE CHURCH RLT
2 HOA RIANO RT OC VBR3
4
5 MID PIPE CORP CON COY
6 STE DAAS ST STE LIB TX ML
With my macro the result I'm having:
Code:
ColumnA ColumnB
1 NACLE CHURCH RLT RLT
2 HOA RIANO RT OC VBR VBR
3 COY 'placed in the wrong position
4 ML 'placed in the wrong position
5 MID PIPE CORP CON COY
6 STE DAAS ST STE LIB TX ML
My expected output:
Code:
ColumnA ColumnB
1 NACLE CHURCH RLT RLT
2 HOA RIANO RT OC VBR VBR
3
4
5 MID PIPE CORP CON COY COY
6 STE DAAS ST STE LIB TX ML ML
Last edited: