Splitting cell entries of variable length
Hi Joe,
However, there is one bug - Do you think you can llook into it?
Some entries in Col D are blank. Now when the program hits an empty
cell, it stops, and throws up an error, saying "Application-defined or
object-defined error".
Try:
'=============
Public Sub TesterX2()
Dim SH As Worksheet
Dim rng As Range
Dim rCell As Range
Dim LRow As Long
Dim sStr As String
Dim arr As Variant
Dim i As Long
Application.ScreenUpdating = False
Set SH = ActiveSheet
LRow = SH.Cells(Rows.Count, "D").End(xlUp).Row
Set rng = SH.Range("D2:D" & LRow)
For Each rCell In rng.Cells
With rCell
sStr = .Value
If Not IsEmpty(.Value) Then
arr = Split(sStr, " ")
i = UBound(arr) - LBound(arr) + 1
rCell(1, 2).Resize(1, i).Value = arr
End If
End With
Next rCell
Application.ScreenUpdating = True
End Sub
'<<=============
---
Regards,
Norman
|