View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Simple Parsing Question in Excel 2000

So you want to look at A12:A60 (49 cells) and put them in B5:E5, B6:E6, ...

If yes, then still with all the (un!)necessary checks:

Option Explicit
Sub testme()
Dim myRng As Range
Dim myCell As Range
Dim DestCell As Range
Dim TopDest As Range
Dim myArr As Variant
Dim iCtr As Long
Dim nCtr As Long

Set myRng = ActiveSheet.Range("a12:a60") 'about 49 cells
Set TopDest = ActiveSheet.Range("B5")

For Each myCell In myRng.Cells
Set DestCell = TopDest
myArr = Split(Application.Trim(myCell.Value), " ")
nCtr = 0
For iCtr = LBound(myArr) To UBound(myArr)
If IsNumeric(myArr(iCtr)) Then
DestCell.Value = myArr(iCtr)
Set DestCell = DestCell.Offset(0, 1)
nCtr = nCtr + 1
If nCtr = 4 Then
Exit For
End If
End If
Next iCtr
Set TopDest = TopDest.Offset(1, 0)
Next myCell

End Sub

====
Without those validity checks, you could modify Tom's code like:

Option Explicit
Sub abc()
Dim s As String
Dim v As Variant
Dim myCell As Range
Dim myRng As Range
Dim DestCell As Range

With ActiveSheet
Set myRng = .Range("a12:a60")
Set DestCell = .Range("B5")
End With

For Each myCell In myRng.Cells
s = myCell.Value
v = Split(Application.Trim(s), " ")
DestCell.Resize(1, 4) = v
Set DestCell = DestCell.Offset(1, 0)
Next myCell

End Sub

(but I like white space!)



wrote:

Dave,

Your code worked like a charm. I made two small mistakes which I'm
sure will be easy to correct.

When I set it up I forget to say I wanted the data in B5, C5, D5, E5
instead of B5, B6, B7, B8.

Also I need to run this identical routine 7 times on 7 cell addresses.

Thanks again, you guys are terrific...


--

Dave Peterson