Hello,
I have the following code which I want to amend to skip rows where there is no data. This macros looks at column J where there can be concatenated values, deiminated by a comma. The code then splits the concatenated values over new lines immediately below, copying the other columns with it. Finally, before moving on to the next row, Excel deletes the original row.
Sometimes column J is null and contains no values at all. In this instance, this is throwing an error and causing corruption in the results. I then see a particular record has values that don't belong to it once the macro has been run.
I'd like to amend the code below to check each time, if column J has data in it. If not, then go to the next row, without deleting this current row. It then goes to the next row with data and splits the concatenated data over as many rows as there are items to split ie ("car, bus, train" creates 3 new lines) and deletes the original line,
Thanks in advance if you can help.
I have the following code which I want to amend to skip rows where there is no data. This macros looks at column J where there can be concatenated values, deiminated by a comma. The code then splits the concatenated values over new lines immediately below, copying the other columns with it. Finally, before moving on to the next row, Excel deletes the original row.
Sometimes column J is null and contains no values at all. In this instance, this is throwing an error and causing corruption in the results. I then see a particular record has values that don't belong to it once the macro has been run.
I'd like to amend the code below to check each time, if column J has data in it. If not, then go to the next row, without deleting this current row. It then goes to the next row with data and splits the concatenated data over as many rows as there are items to split ie ("car, bus, train" creates 3 new lines) and deletes the original line,
Thanks in advance if you can help.
VBA Code:
Sub ProcessCRM()
Dim lastrow As Integer
Dim i As Integer
Dim descriptions() As String
With Worksheets("Clients")
lastrow = .Range("J2").End(xlDown).Row
For i = lastrow To 2 Step -1
If InStr(1, .Range("J" & i).Value, ",") <> 0 Then
descriptions = Split(.Range("J" & i).Value, ",")
End If
For Each Item In descriptions
.Range("J" & i).Value = Item
.Rows(i).Copy
.Rows(i).Insert
Next Item
.Rows(i).EntireRow.Delete
Next i
End With
With Worksheets("Clients")
lastrow = .Range("J2").End(xlDown).Row
For i = 2 To lastrow
.Cells(i, "J").Value = Trim(.Cells(i, "J").Value)
Next i
End With
End Sub