简体   繁体   中英

How to copy a row of data from one sheet to another based on cell data

I'm using excel for a project management tool. Right now I have a large table with a series of drop down menus for users to select who is responsible for the project, due dates, etc.

What I'd like to be able to do is copy over the full row (all project data) to each user individual page.

Say "Fred" creates a project and assigns it to "Tom" on the master page, I want Tom's sheet to autopopulate with the project details so instead of scrolling through the list to find him own name, he can click on his tab at the bottom of the master list and see all of his projects.

I've read through several questions somewhat similar and have yet to find anything that works.

For reference, the names are all in column F and there are currently 12 names that user can select from to assign a project; therefore, there are also 12 blank pages/sheets tabbed at the bottom next to the master page tab.

Thanks for any help you may be able to offer!

This macro might work for you - you need to put the right column number in for the filter...

It has to be put in the "Workbook" code (not a module - otherwise the event handling won't work).

It will run every time you change sheets - and will copy the most up to date information into the project leader's tab. If you have "other" sheets that you don't want this to act upon, you must catch the names of those sheets in the same line where code currently tests for "Master".

Changes needed to adapt to your specific situation - I'm sure you can handle it.

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim prjLeader As String
Dim wholeRange As Range

prjLeader = Sh.Name
If prjLeader = "Master" Then Exit Sub  ' whatever the name of the master sheet is...

On Error GoTo outtahere

Application.EnableEvents = False
Application.ScreenUpdating = False
Sh.UsedRange.Clear                     ' remove "old" information

ActiveWorkbook.Sheets("Master").Activate
Set wholeRange = ActiveSheet.UsedRange

wholeRange.AutoFilter Field:=6, Criteria1:=prjLeader  ' use the field where proj leader name is (F = 6)
wholeRange.Copy                                       ' copy all filtered data

Sh.Activate                                           ' and paste it in project leader's sheet
Range("A1").PasteSpecial

outtahere:                                 ' handle errors - back to sheet, turn events back on
Sh.Activate
Application.EnableEvents = True
Application.ScreenUpdating = True

End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM