View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
David David is offline
external usenet poster
 
Posts: 31
Default Fill cells with names from list

Perfect!!! You've come through for me again. Many thanks.

--
David

Tom Ogilvy wrote

Subject: Fill cells with names from list
From: "Tom Ogilvy"
Newsgroups: microsoft.public.excel.programming


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