LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 127
Default Correct Macro so that if the person is not in the source docum

Hi Socratis:

I have another macro that is presenting a problem and I have tried several
people for help but they are making it really complicated and the macros
don't work....The problem is: I want the macros to look at Column A on
Worksheet 2 and select all incidence of a particular specialist's login info
in Columns A through L and then copy that data to named Worksheet 1 in Cells
A4 through L17.

The problem with the below macro is that the first instance pops in A4
through L4, but the rest of the incidents pop below in lines 40 something....

Can you help me?

Sub LoginLogoutMarquez()
'
' LoginLogoutMarquez Macro
' Macro recorded 6/23/2007 by Jeannie Vincovich
'
' Keyboard Shortcut: Ctrl+w
'

Dim n As Integer, i As Integer, j As Integer
Dim rng As Range

j = 0

Sheets("Agent Login-Logout").Activate
n = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To n
Sheets("Agent Login-Logout").Activate
If Cells(i, "A").Value = "Diaz 1, Henry" Then
Range("A" & i & ":L" & i).Copy
Sheets("Henry D").Activate
If j = 0 Then
Set rng = Worksheets("Henry D").Range("A4")
rng.Select
Selection.PasteSpecial Paste:=xlPasteValues,
Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
j = j + 1
Else
n = Cells(Rows.Count, "A").End(xlUp).Row + 1
Set rng = Worksheets("Henry D").Range("A" & n)
rng.Select
Selection.PasteSpecial Paste:=xlPasteValues,
Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End If
End If
Next i

End Sub


--
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

 
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
source document changes Liege Excel Discussion (Misc queries) 4 March 23rd 07 09:45 AM
need to correct scanned document all i get is jumbled words stacy Excel Discussion (Misc queries) 4 October 15th 05 07:05 PM
How can you see the name of the person who has a shared document . missmac981 Excel Discussion (Misc queries) 1 July 27th 05 08:07 PM
Drawing info from another source document denny Excel Discussion (Misc queries) 5 July 13th 05 05:57 AM
convert existing Excel into Data source document to link to exist. KayLMPD Excel Discussion (Misc queries) 1 March 29th 05 12:37 PM


All times are GMT +1. The time now is 04:00 PM.

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"