View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
jeannie v jeannie v is offline
external usenet poster
 
Posts: 127
Default Correct Macro so that if the person is not in the source docum

Good Morning, Socratis:

Thank you so much for your help......I will try both versions and see which
is the best for my use.....I will let you know if I have any problems since
I'm so new at macros.

I can't thank you enough for lending your talents and expertise.
--
jeannie v


"Socratis" wrote:

jeannie,

Here are two versions of the edited macro that do what you want.

1) Here you check against each name and if present in the Daily Attendance
sheet, then you update n21 on their named sheet. Note however, that there is
some redundancy in the code, not to mention that if you have a lot of names,
then you would have to type quit a few if statements.

Public Sub FillNames()
Sheets("Daily Attendance").Activate
n = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To n
With Cells(i, "A")
If .Value = "name1" Then
Sheets(.Value).Range("n21").Value = Cells(i, "C").Value
ElseIf .Value = "name2" Then
Sheets(.Value).Range("n21").Value = Cells(i, "C").Value
ElseIf .Value = "name3" Then
Sheets(.Value).Range("n21").Value = Cells(i, "C").Value
End If
End With
Next
End Sub

thus, choice 2 which is shorter and does not require that you enter an if
for each name. In this version you must include all the names in the
attendance sheet, by leave the cell in column c empty.

Public Sub FillNames()
Dim lastRow As Integer

With Sheets("Daily Attendance")
lastRow = .Cells(Rows.Count, "A").End(xlUp).Row
End With

For i = 1 To lastRow
With Sheets("Daily Attendance").Cells(i, "C")
If Not IsEmpty(.Value) Then
Sheets(.Offset(0, -2).Value).Range("n21").Value = .Value
End If
End With
Next
End Sub

HTH.

Cheers,
Socratis

"jeannie v" wrote:

Hi:

This is my macro that I need to fix....If the person does not have any data
on the "Daily Attendance" worksheet, I want it to skip that person's data on
their named worksheet....In other words, if Craig doesn't have anything on
Daily Attendance, I want it to go to the next worksheet and put the correct
data in for that person.....I hope this makes sense.......Any help would be
appreciated......

Sheets("Daily Attendance").Activate
n = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To n
If Cells(i, "A").Value = "Lavendar, Craig" Then
v = Cells(i, "C").Value
Exit For
End If
Next
Sheets("Craig L").Activate
Range("N21").Value = v
Sheets("Daily Attendance").Activate
n = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To n
If Cells(i, "A").Value = "Blackmon, Jack" Then
v = Cells(i, "C").Value
Exit For
End If
Next
--
jeannie v