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

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
18,067
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
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,191,168
Messages
5,985,056
Members
439,936
Latest member
BSR

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
Top