Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Copy Dates and Hours Sub

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!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Copy Dates and Hours Sub

You may want to step through this. I just have DEBUG.PRINT statements for
now. If it's what you need and you have more questions, come back. (this
took some thinking)

Sub AttendanceCode()
Dim Attendance As Range
Dim AttendanceDates As Range
Dim AttDate As Range
Dim Students As Range
Dim Student As Range
Dim StudentDate As Range
Dim mySheet As Worksheet

Dim r As Range
Set mySheet = Sheets("Attendance Letter")

Set Student = mySheet.Range("A33:A150")
Set AttendanceDates = mySheet.Range("X$27:$IV$27")
Debug.Print AttendanceDates.Address
For Each Student In Students
StudentDate = ""
For Each AttDate In AttendanceDates
Attendance = mySheet.Cells(Student.Row, AttDate.Column)
If Not IsEmpty(Attendance) Then
Debug.Print Student.Value, AttDate.Value, Attendance.Value
End If
Next AttDate
Next Student
End Sub


HTH,
Barb Reinhardt
"St@cy" wrote:

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!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Copy Dates and Hours Sub

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!



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default 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!




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Copy Dates and Hours Sub

Okay, I've tried to ease things up a little. I've put the selected student's
dates in row 1 and hours in row 2 (X:IV) on the "Attendance Letter" sheet,
but it includes days absent. I want just the days present to appear in three
columns starting with row 21. I'm still new to VBA, here's my pathetic
attempt, which of course has an error.

Sub PrintAttendance()
RowNum = 21
WhichCol = 1
Set sh = Worksheets("Attendance Letter")
For ColLetter = X To IV
If WhichCol = 18 Then
RowCount = 21
End If
If sh.Range(ColLetter & "2").Value 0 Then
Select Case WhichCol
Case Is <= 17
Range("C" & RowNum).Value = Range(ColLetter & "1").Value
Range("D" & RowNum).Value = Range(ColLetter & "2").Value
RowCount = (RowNum + 1)
WhichCol = (WhichCol + 1)
Case 18 To 34
Range("F" & RowNum).Value = Range(ColLetter & "1").Value
Range("G" & RowNum).Value = Range(ColLetter & "2").Value
RowCount = (RowNum + 1)
WhichCol = (WhichCol + 1)
Case Is 34
Range("I" & RowNum).Value = Range(ColLetter & "1").Value
Range("J" & RowNum).Value = Range(ColLetter & "2").Value
RowCount = (RowNum + 1)
WhichCol = (WhichCol + 1)
End Select
End If
Next ColLetter
End Sub
"St@cy" wrote:

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!



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Copy Dates and Hours Sub

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")
rng3.Copy
sh.Range("C5").PasteSpecial xlValues, transpose:=True
rng4.Copy sh.Range("B4")
sh.Range("B5").PasteSpecial xlValues, Transpose:=True
End With
End Sub

--
Regards,
Tom Ogilvy

"St@cy" wrote in message
...
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!






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Copy Dates and Hours Sub

I'm getting a runtime error 1004,
Paste Special method of Range class failed.

"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")
rng3.Copy
sh.Range("C5").PasteSpecial xlValues, transpose:=True
rng4.Copy sh.Range("B4")
sh.Range("B5").PasteSpecial xlValues, Transpose:=True
End With
End Sub

--
Regards,
Tom Ogilvy

"St@cy" wrote in message
...
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!






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hours between dates Linda RQ[_2_] Excel Discussion (Misc queries) 11 February 24th 09 10:41 PM
Determining work hours between dates / hours Andrew Excel Worksheet Functions 3 July 30th 08 06:38 PM
dates to hours Champ Excel Discussion (Misc queries) 2 July 3rd 08 07:07 PM
working with dates and hours goldenrod59 Excel Worksheet Functions 4 February 8th 07 11:29 PM
Number of hours between 2 dates Mike Proffit Excel Programming 3 October 25th 06 04:11 AM


All times are GMT +1. The time now is 02:01 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"