+ Reply to Thread
Results 1 to 28 of 28

VBA code to import pick'em picks into master sheet

Hybrid View

  1. #1
    Registered User
    Join Date
    07-18-2011
    Location
    Georgia
    MS-Off Ver
    MS Office 2010
    Posts
    16

    VBA code to import pick'em picks into master sheet

    I've created two spreadsheets used for a friendly workplace college pick'em. One spreadsheet is sent out to everyone to send back with their picks and the other is the master where all the picks are compiled. In the past I've opened each person's pick file and copy and pasted their picks in the the master. I'd like to see if some VBA code could make this a lot simpler. I've attached my two spreadsheets (Updated: deleted attachments see lower posts for attachments).

    I would like the code to prompt me to tell it what the master file is and what the weekly pick file is (and after importing one set of picks ask me for another pick file until complete). What I struggle with is how to get the code to match the person's name in the pick file to the master file and paste their picks in that row.

    The code should find the person's name in the weekly pick file (Z2) and find the matching row of data in the master (somewhere in Column A starting in row 3). Once it is found copy their picks in the weekly pick file (AA2:AN2) and paste on the approriate row in columns B-O. Would also like to copy their tie breaker scores in their weekly picks (AO2 & AP2) into the appropriate row in the masters in column R & T respectively.

    Few notes: There will always be 14 games that are picked and there will always be two games scores used for tiebreakers. The weekly pick will always have the same setup and sheet names. The master file sheet name will change each week (Week 2, Week3, etc.) so some option to change the code each week would be nice.

    I appreciate any help anyone would be willing to give. Thanks in advance. -Chad
    Last edited by chadwick140; 08-26-2013 at 08:54 PM.

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: VBA code to import pick'em picks into master sheet

    Hi chadwick140

    I'd be willing to play with this but I don't know how to approach it when the Games in the Weekly Picks aren't the same Games as in the Master File. What am I missing?
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Registered User
    Join Date
    07-18-2011
    Location
    Georgia
    MS-Off Ver
    MS Office 2010
    Posts
    16

    Re: VBA code to import pick'em picks into master sheet

    Sorry should have made them match but I've been "enhancing" the pick sheet this year and just pulled an old sheet from last year for the master. They will match when I finalize it for the first week of the season. Hope that helps you, it shouldn't affect the needed code to copy and paste. Thanks for your time. -Chad

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: VBA code to import pick'em picks into master sheet

    Hi Chad

    Ok...perhaps another will look at this with you. I'll not write the Code and publish it without testing. I'm unable to test with your attached files. Sorry...

  5. #5
    Registered User
    Join Date
    07-18-2011
    Location
    Georgia
    MS-Off Ver
    MS Office 2010
    Posts
    16

    Re: VBA code to import pick'em picks into master sheet

    Content deleted by poster. Incorrect information.
    Last edited by chadwick140; 08-24-2013 at 08:06 PM. Reason: had wrong information

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: VBA code to import pick'em picks into master sheet

    Hi Chad

    It matters not to the Code but I'm curious...why is Mississippi Sate playing two different opponents on the same day?

    Oh, by the way, you have 18 Games in the Master and only 14 in the Weekly Picks. Please post files that represent the same structure as you're actual Files or any Code we write may well fail. Again, this may not matter to the Code...it could matter to you.

    You do the front end work then we'll try to make it work for you...please clean up you're sample Files then we'll work on it...Garbage in...Garbage out...
    Last edited by jaslake; 08-24-2013 at 07:44 PM.

  7. #7
    Registered User
    Join Date
    07-18-2011
    Location
    Georgia
    MS-Off Ver
    MS Office 2010
    Posts
    16

    Re: VBA code to import pick'em picks into master sheet

    Ok...I do apologize apparently when I was trying to find out why you had a problem with the games not matching up I didn't count the columns right and added 4 columns that didn't need to be (my original had the right number, just the games didn't match). I have gone back and made the pick sheet and master file match for this year so now no teams play twice (Also I deleted my post earlier to maybe prevent getting anyone else confused by my mistake).

    Attached are two cleaned up versions. I hope this helps make better sense. thanks again.
    Attached Files Attached Files

  8. #8
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: VBA code to import pick'em picks into master sheet

    Hi Chad

    What will be your Workbook Names?

  9. #9
    Registered User
    Join Date
    07-18-2011
    Location
    Georgia
    MS-Off Ver
    MS Office 2010
    Posts
    16

    Re: VBA code to import pick'em picks into master sheet

    They can be the names of my files I attached above or can simply be one called picks and the other master.

  10. #10
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: VBA code to import pick'em picks into master sheet

    Hi Chad

    I have the Code written to update Master from Weekly Picks. What I still need from you is to explain how each individual's Weekly Picks get inputed into the Weekly Picks Workbook...what's the Source of that information?

    Here's the Code as it currently stands.
    Public sWB As Workbook
    Public sWS As Worksheet
    Public tWB As Workbook
    Public tWS As Worksheet
    Public fname As String
    Public fname1 As String
    Public LR As Long
    Public Rng As Range
    Public cel As Range
    
    Option Explicit
    
    Sub Open_Master_File()
    
        With Application.FileDialog(msoFileDialogOpen)
            .InitialFileName = "C:\Documents and Settings\Administrator\Desktop\chadwick140\New Stuff\Target Files"   'this is the default folder shown
            .AllowMultiSelect = False
            .Filters.Add "All Files", "*.*"        'everything
            .Filters.Add "Excel Files", "*.xl*", 1  'default
            .Show
            If .SelectedItems.Count > 0 Then
                fname = .SelectedItems(1)
            Else
                Exit Sub
            End If
        End With
        Set tWB = Workbooks.Open(fname)
        Set tWS = tWB.Sheets(1)
        Call Open_Weekly_File
    End Sub
    
    
    Sub Open_Weekly_File()
    
        With Application.FileDialog(msoFileDialogOpen)
            .InitialFileName = "C:\Documents and Settings\Administrator\Desktop\chadwick140\New Stuff\Source Files"   'this is the default folder shown
            .AllowMultiSelect = False
            .Filters.Add "All Files", "*.*"        'everything
            .Filters.Add "Excel Files", "*.xl*", 1  'default
            .Show
            If .SelectedItems.Count > 0 Then
                fname1 = .SelectedItems(1)
            Else
                Exit Sub
            End If
        End With
        Set sWB = Workbooks.Open(fname1)
        Set sWS = sWB.Sheets(1)
        Call Fill_Master
    End Sub
    
    
    Sub Fill_Master()
        Dim myName As Range
        sWB.Names.Add Name:="Names", RefersTo:= _
                "=OFFSET('" & sWS.Name & "'!$L$6,0,0,(COUNTA('" & sWS.Name & "'!$L:$L)-1),1)"
    
        With tWS
            LR = .Cells(3, 1).End(xlDown).Offset(0, 0).Row
            Set Rng = .Range("A3:A" & LR)
            For Each cel In Range("Names")
                Set myName = Rng.Find(cel, , xlValues, xlWhole, xlByRows, xlNext, False)
                If Not myName Is Nothing Then
                    sWS.Range("C5").Value = cel
                    myName.Offset(0, 1).Resize(1, 14).Value = sWS.Range("AA2:AN2").Value
                    myName.Offset(0, 17).Value = sWS.Range("AO2").Value
                    myName.Offset(0, 19).Value = sWS.Range("AP2").Value
                End If
            Next cel
        End With
        sWB.Close False
    End Sub
    These two lines of Code will need to be changed to suit your environment.
    .InitialFileName = "C:\Documents and Settings\Administrator\Desktop\chadwick140\New Stuff\Target Files"   'this is the default folder shown
    .InitialFileName = "C:\Documents and Settings\Administrator\Desktop\chadwick140\New Stuff\Source Files"   'this is the default folder shown
    Last edited by jaslake; 08-25-2013 at 03:35 PM.

  11. #11
    Registered User
    Join Date
    07-18-2011
    Location
    Georgia
    MS-Off Ver
    MS Office 2010
    Posts
    16

    Re: VBA code to import pick'em picks into master sheet

    First thank you for trying to help me I really appreciate it.

    Ok first I'll answer your question. 30 our so people will be emailed the weekly picks file. They will then email them back to me with their selections made. Previously I'd open each persons file and copy and paste their picks into the master.

    So I tried the code and it copied and pasted the weekly picks into the master but instead of just for one person it did this for all names. I don't know much about VBA but looking at the code you're looking at column L on the weekly picks and I'm not sure why. It appears you have the games and scores pulled correctly from the weekly but it should be looking at cell Z2 to get the name. Once it gets the name it should then find that person's name and what row in the master and paste their picks on that row in the master.

    Hope this helps, thanks again. -Chad

  12. #12
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: VBA code to import pick'em picks into master sheet

    Hi Chad

    This is the piece I'm missing
    I'd open each persons file
    What I want to do is get each persons picks into the Weekly Picks File...the Code will then transfer each persons picks into the Master.

    Depending on the Structure of each persons Pick File, we may be able to bypass the Weekly Picks File altogether. At the moment the Code has no way to discern the individual persons Picks. Need to know where to get them.

    If you please, show me what an individual Pick File looks like.

  13. #13
    Registered User
    Join Date
    07-18-2011
    Location
    Georgia
    MS-Off Ver
    MS Office 2010
    Posts
    16

    Re: VBA code to import pick'em picks into master sheet

    The Weekly Picks file is each persons pick file. All the individuals see in the picks file is columns A-J. In cell C5 the individual will pick their name (currently just Name1, Name2, etc.) and then make their picks. In preparation to make it easy to copy and paste into the master I made columns AA-AN equal what they picked to be easier to copy and paste.

    Each week I will go in and change the games in the weekly pick file and then send it out again so the format will not change to the individual.

    If this still doesn't make sense let me know.

  14. #14
    Registered User
    Join Date
    07-18-2011
    Location
    Georgia
    MS-Off Ver
    MS Office 2010
    Posts
    16

    Re: VBA code to import pick'em picks into master sheet

    Ok I've changed a few things and the code now does what I want it to. While I'm sure there are things in the code not right (as it still has a reference to column L in the Sub Fill Master it works. If you can tell me what I can delete that would be great if not Thank you so much for your help. (Changes I made are blue)

    Also, anyway I can make the target worksheet name equal a cell on the source file? Say I put Week 1 in Z1 on the weekly picks it will import into Sheet Week 1 in the master. If it Z1=Week 2 it would attempt to import to sheet Week 2 (which doesn't exist in my example file but will as the season goes on). If not I've tried and figured out if I just keep the current weeks sheet listed first in the master file it imports in the correct sheet. Thanks again.

    Public sWB As Workbook
    Public sWS As Worksheet
    Public tWB As Workbook
    Public tWS As Worksheet
    Public fname As String
    Public fname1 As String
    Public LR As Long
    Public Rng As Range
    Public cel As Range
    
    Option Explicit
    
    Sub Open_Master_File()
    Application.ScreenUpdating = False
        With Application.FileDialog(msoFileDialogOpen)
            .Title = "Master file..."
            .InitialFileName = "C:\Users\Layne\Desktop\"   'this is the default folder shown
            .AllowMultiSelect = False
            .Filters.Add "All Files", "*.*"        'everything
            .Filters.Add "Excel Files", "*.xls*", 1  'default
            .Show
            If .SelectedItems.Count > 0 Then
                fname = .SelectedItems(1)
            Else
                Exit Sub
            End If
        End With
        Set tWB = Workbooks.Open(fname)
        Set tWS = tWB.Sheets(1)
        Call Open_Weekly_File
    End Sub
    
    
    Sub Open_Weekly_File()
    
        With Application.FileDialog(msoFileDialogOpen)
            .Title = "weekly pick file..."
            .InitialFileName = "C:\Users\Layne\Desktop\"   'this is the default folder shown
            .AllowMultiSelect = False
            .Filters.Add "All Files", "*.*"        'everything
            .Filters.Add "Excel Files", "*.xls*", 1  'default
            .Show
            If .SelectedItems.Count > 0 Then
                fname1 = .SelectedItems(1)
            Else
                Exit Sub
            End If
        End With
        Set sWB = Workbooks.Open(fname1)
        Set sWS = sWB.Sheets(1)
        Call Fill_Master
    End Sub
    
    
    Sub Fill_Master()
        Dim myName As Range
        sWB.Names.Add Name:="Names", RefersTo:= _
                "=OFFSET('" & sWS.Name & "'!$z$2,0,0,(COUNTA('" & sWS.Name & "'!$L:$L)-1),1)"
    
        With tWS
            LR = .Cells(3, 1).End(xlDown).Offset(0, 0).Row
            Set Rng = .Range("A3:A" & LR)
            For Each cel In Range("Names")
                Set myName = Rng.Find(cel, , xlValues, xlWhole, xlByRows, xlNext, False)
                If Not myName Is Nothing Then
                    sWS.Range("C5").Value = cel
                    myName.Offset(0, 1).Resize(1, 14).Value = sWS.Range("AA2:AN2").Value
                    myName.Offset(0, 17).Value = sWS.Range("AO2").Value
                    myName.Offset(0, 19).Value = sWS.Range("AP2").Value
                End If
            Next cel
        End With
        sWB.Close False
        Call Open_Weekly_File 'Continue to ask to import weekly picks 
    End Sub

  15. #15
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: VBA code to import pick'em picks into master sheet

    Hi Chad

    Let me understand your process...

    Each week you Email the Weekly Picks File to each Name. This File is of the same structure as the "weekly picks Rev2.xlsx" I've been working with; only difference is Columns K through AP are hidden.

    The Name selects his/her Picks and Emails the File back to you. You download and save each of the attached Files. Where do you save the Files as they're returned and how do you name them? What I wish to do is grab each of these individual Files, loop through them and process their Picks to the Master File. The Code will find and open each of the Files, one by one, and post to the Master. No selecting required.

    Regarding this
    anyway I can make the target worksheet name equal a cell on the source file
    Yes, this is possible. I'll think about it and make a recommendation. Please get back to me.

  16. #16
    Registered User
    Join Date
    07-18-2011
    Location
    Georgia
    MS-Off Ver
    MS Office 2010
    Posts
    16

    Re: VBA code to import pick'em picks into master sheet

    Yes that is how the process works. I save the files in different folders for each week for example "H:\Desktop\CFB Pickem\Wk 1 Picks\" then next week picks go into "H:\Desktop\CFB Pickem\Wk 2 Picks\". As far as naming them (last year I didn't because i just open from their email and copied and paste) I was planning on just adding maybe their last name to the end of the file name so filename is sent out as "Games - WEEK 1.xlsx" so I might save them this year "Games - WEEK 1 - Johnson.xlsx". So yeah if there is a way to just tell it go look in Wk 1 Picks and run the process for all the files in that folder that would be great. Only that week's picks are kept in that folder so all files in their should go through the process. The master file and other files are kept in the folder one up "CFB Pickem".

    Thanks again for your help.

  17. #17
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: VBA code to import pick'em picks into master sheet

    Hi Chad

    Is it SOLVED? Shall I stop working on it?

  18. #18
    Registered User
    Join Date
    07-18-2011
    Location
    Georgia
    MS-Off Ver
    MS Office 2010
    Posts
    16

    Re: VBA code to import pick'em picks into master sheet

    Look this is the first time I've posted a question. I've always searched this forum and found answers I needed couldn't to this issue. I don't know the protocol, I felt the bulk of the issue was solved so I marked it as so. I think now we are just fine tuning it. I would like you to continue to work on what you were talking about where I wouldn't select indivual files it would maybe read all files in a folder. If I need to mark as unsolved I will.

  19. #19
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: VBA code to import pick'em picks into master sheet

    Hi Chad

    This is your call
    If I need to mark as unsolved I will
    Most members of the Forum, including me, will not look at a SOLVED Thread except for insight into solutions they're researching.

    If you wish it fine tuned to work as you'd like...use your judgment...I'll continue to pursue it...if not...glad I could help. Let me know.

  20. #20
    Registered User
    Join Date
    07-18-2011
    Location
    Georgia
    MS-Off Ver
    MS Office 2010
    Posts
    16

    Re: VBA code to import pick'em picks into master sheet

    I've marked it as unsolved. Please continue to help, would like to make this the best it can be and you've done a tremendous job thus far.

  21. #21
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: VBA code to import pick'em picks into master sheet

    Hi Chad

    The following Code is in the attached Code Book v2.xlsm along with a UserForm. The UserForm will ask you to Select a Week to Process. I'm attaching six files (five attached to this Post...the sixth will be attached to a follow-up post)

    They should be placed like this Directory Tree

    Folder H:\Desktop\CFB Pickem\ <------ Call this whatever you like...put it wherever you like
    Code Book v2.xlsm
    Target Files\
    picks master.xlsx
    Wk 1 Picks\
    Games - Week1 - Harry Cary.xlsx
    Games - Week1 - Joe Johnson.xlsx
    Games - Week1 - Mary Mary.xlsx
    Games - Week1 - Pete Smith.xlsx
    Run the Code from the Button in Code Book v2.xlsm. Let me know of issues.
    Public sWB As Workbook, tWB As Workbook
    Public sWS As Worksheet, tWS As Worksheet
    Public LR As Long
    Public Rng As Range, cel As Range
    Public myPath As String, myFile As String, PickName As String
    
    Option Explicit
    
    Sub Open_Master_File()
        Application.ScreenUpdating = False
    
        myPath = ThisWorkbook.Path & "\Target Files\"
        Application.Workbooks.Open (myPath & "picks master.xlsx")
        Set tWB = ActiveWorkbook
    
        UserForm1.Show
    
        If IsNull(UserForm1.ListBox1.Value) Then
            ActiveWorkbook.Close False
            Exit Sub
        End If
    
        Set tWS = tWB.Sheets(UserForm1.ListBox1.Value)
        tWS.Activate
        Call Open_Weekly_File
    End Sub
    
    
    Sub Open_Weekly_File()
    
        myPath = ThisWorkbook.Path & "\" & UserForm1.ListBox1.Value & " Picks" & "\"
        myFile = Dir(myPath)
    
        Do While myFile <> ""
            If myFile Like "*.xlsx" Then
                Workbooks.Open myPath & myFile
                Set sWB = ActiveWorkbook
                Set sWS = sWB.Sheets(1)
                PickName = sWS.Range("C5").Value
                Call Fill_Master
                ActiveWorkbook.Close False
            End If
            myFile = Dir
        Loop
    End Sub
    
    
    Sub Fill_Master()
        Dim myName As Range
    
        With tWS
            LR = .Cells(3, 1).End(xlDown).Offset(0, 0).Row
            Set Rng = .Range("A3:A" & LR)
            Set myName = Rng.Find(PickName, , xlValues, xlWhole, xlByRows, xlNext, False)
            If Not myName Is Nothing Then
                myName.Offset(0, 1).Resize(1, 14).Value = sWS.Range("AA2:AN2").Value
                myName.Offset(0, 17).Value = sWS.Range("AO2").Value
                myName.Offset(0, 19).Value = sWS.Range("AP2").Value
            End If
        End With
    End Sub
    Attached Files Attached Files

  22. #22
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: VBA code to import pick'em picks into master sheet

    Hi Chad...attached is the sixth File
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Formula in one cell that picks up another based on dates provided in the same sheet
    By s.tara91 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-16-2013, 12:58 AM
  2. vba code for master sheet
    By kandre in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-21-2013, 10:17 AM
  3. VBA Sheet array code not working with drop down lists in master sheet
    By chiplaidlaw in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-03-2012, 11:01 AM
  4. Replies: 2
    Last Post: 07-17-2008, 08:37 AM
  5. Validation Pick Lists: Picks containing spaces
    By ComcoDG in forum Excel General
    Replies: 11
    Last Post: 07-15-2008, 04:42 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1