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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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,213,538
Messages
6,114,220
Members
448,554
Latest member
Gleisner2

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