Home |
Search |
Today's Posts |
#7
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
source document changes | Excel Discussion (Misc queries) | |||
need to correct scanned document all i get is jumbled words | Excel Discussion (Misc queries) | |||
How can you see the name of the person who has a shared document . | Excel Discussion (Misc queries) | |||
Drawing info from another source document | Excel Discussion (Misc queries) | |||
convert existing Excel into Data source document to link to exist. | Excel Discussion (Misc queries) |