Splitting text in two columns based on condition and deleting row

rdev

Active Member
Joined
Dec 3, 2007
Messages
273
I have the following in cell C4

*****2018_Land and Building

I need to split the 2018 to column F , making the 2018 which is a text to a number and split the "Land and building" to column G of same row , further if "_" is not found in row 4 , then the row is to be deleted altogether. The first line of data is in cell C3

How can this be automated, the procedure should cover up to the last row in Coumn C

Thx
 
Last edited:

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
I have the following in cell C4

*****2018_Land and Building

I need to split the 2018 to column F , making the 2018 which is a text to a number and split the "Land and building" to column G of same row , further if "_" is not found in row 4 , then the row is to be deleted altogether. The first line of data is in cell C3

How can this be automated, the procedure should cover up to the last row in Coumn C

Thx
Assuming your data have only * as the leading characters, see if this works for you.
Code:
Sub rdev()
Dim R As Range, i As Long, V As Variant
Set R = Range("C3:C" & Cells(Rows.Count, "C").End(xlUp).Row)
Application.ScreenUpdating = False
For i = R.Rows.Count To 1 Step -1
    If InStr(R(i), "_") = 0 Then
        R.Rows(i).EntireRow.Delete
        GoTo Nx
    Else
       V = Split(Replace(R(i), "*", ""), "_")
       R(i).Offset(0, 4).Value = V(0)
       R(i).Offset(0, 5).Value = V(1)
    End If
Nx:
Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,586
Messages
6,125,683
Members
449,249
Latest member
ExcelMA

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top