View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Fill cells with names from list


Assumes all processing is done on the activesheet. code has been tested
and works exactly as I designed it.

Sub CopyNames()
Dim rng As Range, rng1 As Range
Dim cnt As Long, cnt1 As Long
Dim i As Long, sAddr As String
Dim rng2 As Range
Set rng = Range("Students")
cnt = Application.CountIf(Columns(1), "*Total Class Hours*")
cnt1 = Application.CountA(rng)
If cnt1 cnt Then
MsgBox "Only " & cnt & " Students will be processed"
End If
Set rng1 = Columns(1).Find(What:="Total Class Hours", _
After:=Range("A65536"), _
LookIn:=xlConstants, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not rng1 Is Nothing Then
i = 1
sAddr = rng1.Address
Do
If i = 1 Then
' Change A2 to the cell to get the
' first name
Range("A2").Value = rng(i)
Else
rng2.Offset(1, 0).Value = rng(i)
End If
i = i + 1
Set rng2 = rng1
Set rng1 = Columns(1).FindNext(rng2)
Loop Until i cnt Or rng1.Address = sAddr
End If
End Sub

--
Regards,
Tom Ogilvy


"David" wrote in message
...
Just to elaborate, here's what I want to happen:
Get the 1st name out of Range("Students")
Copy it after the 1st instance of "Total Class Hours"
Get the 2nd name out of Range ("Students")
Copy it after the 2nd instance of "Total Class Hours"
Get the 3rd name out of Range ("Students")
Copy it after the 3rd instance of "Total Class Hours"

and so on... until all new names are copied

And remember, I want to preserve the format of each
cell with a name in it (they are shaded light green)

--
David
Tom Ogilvy wrote

Subject: Fill cells with names from list
From: "Tom Ogilvy"


<<snip