Copy Dates and Hours Sub
Well, it did something.. hum?
I guess I need to make sure it pastes values only. I need the dates and
hours to make two columns starting at C21 (the dates) and D21 (the hours).
So far, the sub only printed the first dates hours, then all #Value! and #NA
horizonally from there.
"Tom Ogilvy" wrote:
Sub ABC()
PrintAttendance "Stew"
End Sub
Sub PrintAttendance(student)
Dim rng As Range, rng1 As Range
Dim rng2 As Range, rng3 As Range
Dim rng4 As Range, res As Variant
Dim sh as Worksheet
With Worksheets("Attendance")
Set rng = .Range("A33:A150")
res = Application.Match(student, rng, 0)
If IsError(res) Then
MsgBox student & " was not found"
Exit Sub
End If
Set rng1 = rng(res)
Set rng2 = Intersect(.Range("X:IV"), rng1.EntireRow)
Set rng3 = Nothing
On Error Resume Next
Set rng3 = rng2.SpecialCells(xlConstants, xlNumbers)
On Error GoTo 0
If rng3 Is Nothing Then
MsgBox student & " has no attendance"
Exit Sub
End If
Set rng4 = Intersect(.Rows(27), rng3.EntireColumn)
set sh = Worksheets("Attendance Letter")
sh.Range("B4").Resize(2,250).ClearContents
rng3.Copy sh.Range("B5")
rng4.Copy sh.Range("B4")
End With
End Sub
worked for me. It pastes the dates and hours to Range B4 and B5 of
Attendance Letter. Adjust to copy to the proper location.
--
Regards,
Tom Ogilvy
"St@cy" wrote in message
...
I'm trying to make a sub PrintAttendance (student).
On sheet "Attendance Letter", I want to copy the dates and hours (skipping
days absent) of a selected student. On sheet "Attendance", the student's
names are located A33:A150, their attendance hours X33:IV150 (each row a
different student), and the corresponding dates are located $X$27:$IV$27.
So far, I just have a mess. Please help me!
|