+ Reply to Thread
Results 1 to 17 of 17

Transfer Data from Userform to Worksheet Table

Hybrid View

  1. #1
    Registered User
    Join Date
    06-25-2011
    Location
    Scotland
    MS-Off Ver
    Excel 2013 / 2016
    Posts
    69

    Transfer Data from Userform to Worksheet Table

    Hi, I have a sports workbook to record data of up to 20 teams which works well except it takes too long to enter all the data, so to speed things up I created a USERFORM that selects the players into their playing positions…… Works ok

    The issue I have is that once the players have been selected in 10 different textboxes named Tbx1 to Tbx10 I need some code that

    1. Looks at the week number in a combobox (CbxWeek).
    2. On a click of the Transfer command button it puts the players playing position in to the main table in the correct week column (W1 in the example).
    3. It would warn if the W1 etc Cells were already populated.


    Example

    Name Team W1 W2 W3
    A. Smith 5 Team A 3
    A. Smith 6 Team A 5

  2. #2
    Registered User
    Join Date
    06-25-2011
    Location
    Scotland
    MS-Off Ver
    Excel 2013 / 2016
    Posts
    69

    Re: Transfer Data from Userform to Worksheet Table

    Better exapmle

    Table eg.JPG

  3. #3
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Transfer Data from Userform to Worksheet Table

    can you upload a sample workbook?
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  4. #4
    Registered User
    Join Date
    06-25-2011
    Location
    Scotland
    MS-Off Ver
    Excel 2013 / 2016
    Posts
    69

    Re: Transfer Data from Userform to Worksheet Table

    Mike, Thanks for replying & I have made an example sheet but for some reason the attach button isn't working..... So frustrating

    Capture1.JPG

    Capture2.JPG

    Userform.xlsm
    Last edited by How How; 01-08-2017 at 02:06 PM.

  5. #5
    Registered User
    Join Date
    06-25-2011
    Location
    Scotland
    MS-Off Ver
    Excel 2013 / 2016
    Posts
    69

    Re: Transfer Data from Userform to Worksheet Table

    Mike, it appears I was able to attach the file using insert image!!

  6. #6
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Transfer Data from Userform to Worksheet Table

    Are those all buttons next to the names? You can upload a work by clicking the Go Advanced and scrolling down to Manage Attachments and attaching your workbook

  7. #7
    Registered User
    Join Date
    06-25-2011
    Location
    Scotland
    MS-Off Ver
    Excel 2013 / 2016
    Posts
    69

    Re: Transfer Data from Userform to Worksheet Table

    Mike, Yes they are all buttons. The file is attached under the screenshots (Namemed "userform,xlsm")

  8. #8
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Transfer Data from Userform to Worksheet Table

    Okay I see it now, I will work on this while I watch these NFL Playoff games. So give me a little time

  9. #9
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Transfer Data from Userform to Worksheet Table

    Take a look at the attached workbook. I did away with the Textbox's and Buttons and added a Listbox. Added code to the Team Combobox Change Event to load names to your Listbox. When the Names are loaded to the Listbox, I'm adding the Row number to Column 2 of the Listbox. This used to write back the data to the sheet.

    To find the column for the week, I'm using the Right(ComboxTeam.Value,1) to get what week. And Looking for "W" & Right(ComboxTeam.Value,1) in row 1.
    Attached Files Attached Files

  10. #10
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Transfer Data from Userform to Worksheet Table

    Duplicate post

  11. #11
    Registered User
    Join Date
    06-25-2011
    Location
    Scotland
    MS-Off Ver
    Excel 2013 / 2016
    Posts
    69

    Re: Transfer Data from Userform to Worksheet Table

    Mike, was having prods opening but got it now....... I've had a play with it & it is defo better than the way I had it set up...... The fact once you select a player it is removed from the 1st listbox...... That will stop accidental duplicates.

    Thank you very much.......

    I'm going to add a button to open another userform to add a player & team to the sheet my code so far is below

    P.s in my real worksheet I have Col b = last name, col C = First name & col D = full name via a formula, Col F is the team...... Is this the best way?

    Private Sub CmdAddPlayer_Click()
    
    Dim x As Range                 '   Declare a variable as a range object
    
    For Each x In Range("B:B")     '  Search for our range object inside column A
    
    If x.Value = "" Then           '   Check whether cell value is blank
    
    x.Select                       '   Select the cell
    
    ActiveCell = TbxLastName.Text
    
    ActiveCell.Offset(0, 1).Select
    
    ActiveCell = TbxFirstName.Text
    
    ActiveCell.Offset(0, 2).Select
    
    ActiveCell = CbxTeam.Text
    
    
    Exit For                         '   Stop searching
    
    End If                           '  End condition
    
    Next x                           '  End loop
    
    End Sub
    Last edited by How How; 01-08-2017 at 08:39 PM.

  12. #12
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Transfer Data from Userform to Worksheet Table

    Cleaned up your code some. No need to select cells. I guess I'm lost to why you have another userform? Are you using my updated workbook or are you still using yours?

    Private Sub CmdAddPlayer_Click()
    Dim cell As Range                   '   Declare a variable as a range object
    
     For Each cell In Range("B:B")      '  Search for our range object inside column A
        If cell.Value = "" Then         '  Check whether cell value is blank
            'cell.Select                '  Dont need to select cell.
            cell.Value = TbxLastName.Text
            cell.Offset(0, 1) = TbxFirstName.Text
            cell.Offset(0, 2) = CbxTeam.Text
           Exit For                     '  Stop searching
        End If                          '  End condition
     Next cell                          '  End loop
    
    End Sub
    Last edited by mike7952; 01-09-2017 at 08:23 AM.

  13. #13
    Registered User
    Join Date
    06-25-2011
    Location
    Scotland
    MS-Off Ver
    Excel 2013 / 2016
    Posts
    69

    Re: Transfer Data from Userform to Worksheet Table

    Mike, If choosing the players & a "new" player has played, that player will not be in the list when choosing the ten players so I have added a button to add a player & his team to the main excel sheet via a 2nd userform triggered from your userform...... Lazy but quicker!! (Players can be added throughout the season & remember could be as much as 20 teams).

    Thanks again...... I will try & learn from the codes you have supplied....... I spend hours/days doing this but I must enjoy it!!

    I only have 1 concern in that the position numbers can be overwritten if the wrong week is accidently selected but I will try to put a check in your code prior to writing the positions.

    Your help is very much appreciated

  14. #14
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Transfer Data from Userform to Worksheet Table

    You do something like this to check the range and a Message box to either clear the range and rewrite the cells or cancel.

    Sub FindFirstLast()
        Dim vaValues As Variant
        Dim vaFilter As Variant
        Dim lFirst As Long
        Dim lLast As Long
    
        Const sFIND As String = "Team A"
    
        With Application.WorksheetFunction
            'Get a 1-d array from a column
            vaValues = .Transpose(Worksheets("Names").Range("C1:C80").Value)
            'Use match to get the first instance
            lFirst = .Match(sFIND, vaValues, False)
            'Filter on the values
            vaFilter = Filter(vaValues, sFIND)
            'Assumes they're all together
            lLast = lFirst + UBound(vaFilter)
            
            MsgBox "Range for " & sFIND & "Week 1 is: Range(D" & lFirst & ":D" & lLast & ")"
            ' Then we can use the CountA Function to check range for values
            MsgBox .CountA(Range("D" & lFirst & ":D" & lLast))
        End With
    End Sub

  15. #15
    Registered User
    Join Date
    06-25-2011
    Location
    Scotland
    MS-Off Ver
    Excel 2013 / 2016
    Posts
    69

    Re: Transfer Data from Userform to Worksheet Table

    Thanks Mike, I've got it all working with my "real" workbook except the last bit of code that checks if positions have been already entered. I was hoping to find a way that when the add players button was pressed it would take the team & week number from the userform CbxTeam & CbxWeek combo boxes then do a count to see the team had numbers already entered in that week

    IF Team B & Week 3 was selected in the userform then if ant numbers were found it would have exit without overwriting.

    I did try your code & it worked for individual columns, could I use that for the above if I referenced the userform combo boxes?

  16. #16
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Transfer Data from Userform to Worksheet Table

    Replace your btnAddPlayers with the code below.

    Private Sub btnAddPlayers_Click()
     Dim iColumn As Long
     Dim iLooper As Long
     
     If lstSelectedPlayers.ListCount = 0 Then Exit Sub
     
     On Error Resume Next
     With Worksheets(shName)
        iColumn = .Cells(1).EntireRow.Find("W" & Right(Me.CbxWeek.Value, 1), , xlValues, xlWhole, xlByColumns, False).Column
     End With
     If Err.Number <> 0 Then Err.Clear: Exit Sub
     If CheckIfDataAlreadyEntered(iColumn, Me.CbxTeam.Value) > 0 Then
        MsgBox "Your message"
       Exit Sub
     End If
     ' Uses 2nd Column in the Listbox that stores the row that Player is on
     With lstSelectedPlayers
        For iLooper = 0 To .ListCount - 1
           Cells(.List(iLooper, 1), iColumn) = iLooper + 1
        Next
        .Clear
        Label2.Caption = "Count :" & .ListCount
     End With
    End Sub
    Add this code in Standard module where you have your SmileyFace1_Click

    Function CheckIfDataAlreadyEntered(WhatColumn As Long, WhatTeam As String) As Long
        Dim vaValues As Variant
        Dim vaFilter As Variant
        Dim lFirst As Long
        Dim lLast As Long
    
        With Application.WorksheetFunction
            'Get a 1-d array from a column
            vaValues = .Transpose(Range(Cells(1, "C"), Cells(Rows.CountLarge, "C")).Value)
            'Use match to get the first instance
            lFirst = .Match(WhatTeam, vaValues, False)
            'Filter on the values
            vaFilter = Filter(vaValues, WhatTeam)
            'Assumes they're all together
            lLast = lFirst + UBound(vaFilter)
            
            CheckIfDataAlreadyEntered = .CountA(Range(Cells(lFirst, WhatColumn).Address, Cells(lLast, WhatColumn).Address))
        End With
    End Function

  17. #17
    Registered User
    Join Date
    06-25-2011
    Location
    Scotland
    MS-Off Ver
    Excel 2013 / 2016
    Posts
    69

    Re: Transfer Data from Userform to Worksheet Table

    Mike......... Absolutely perfect, I appreciate you have done more than the original query....Thank you very much

+ 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. Data Transfer: Userform to Worksheet
    By smartbuyer in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-24-2014, 01:15 PM
  2. [SOLVED] Transfer Userform data on 1 worksheet to different worksheet (empty row = wrong sheet)
    By HeyInKy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-26-2014, 10:08 AM
  3. combining chart userform and data transfer userform into 1 userform
    By H_Kennedy in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-03-2014, 12:28 PM
  4. [SOLVED] Userform transfer data into worksheet
    By kheytli in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-30-2013, 01:09 PM
  5. UserForm to transfer items from one table to another table in the next empty cell...
    By aneese11 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-04-2012, 10:31 AM
  6. Replies: 20
    Last Post: 05-24-2012, 10:51 AM
  7. Transfer Data From Userform to Worksheet
    By ScotyB in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-21-2012, 07:12 AM

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