Find problem
I'm trying to search one file for a staff number and then copy the
information in the cells to the right into another file.
The problem is with "Cells.Find(What:=Windows("users.xls").ActiveC ell,
......."
I want to search for the contents of the currently selected cell of the
other sheet.
Another way to do this would be to copy and then search for the
contents of the clipboard but I couldn't find any examples of that
either.
I also tried to copy the number to a variable and search for the
variable name but that didn't work for me. (2nd piece of code)
Thanks for any help. I should hopefully soon have my first piece of VBA
code written!
' Switch to sheet to fill
Windows("users.xls").Activate
Range("c104").Select
' Switch to sheet to search
Windows("list.xls").Activate
' Search the sheet for staff number as selected in other sheet
Cells.Find(What:=Windows("users.xls").ActiveCell, After:="A1",
LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, MatchCase:=False).Activate
' Select the cells to the right of what is found and copy
Range(ActiveCell, ActiveCell.End(xlToRight)).Select
Application.CutCopyMode = False
Selection.Copy
' Switch to sheet to fill to paste results
Windows("users.xls").Activate
' The correct cell will be active, paste.
ActiveSheet.Paste
' Repeat
ActiveCell.Offset(1, 0).Select
' Switch to sheet to fill
Windows("users.xls").Activate
Range("c104").Select
staffnumber = ActiveCell.Value
' Switch to sheet to search
Windows("list.xls").Activate
' Search the sheet for staff number as selected in other sheet
Cells.Find(What:=staffnumber, After:="A1", LookIn:=xlFormulas,
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False).Activate
|