+ Reply to Thread
Results 1 to 21 of 21

Excel 2007 : How to transfer data from worksheet to vba userform

  1. #1
    Registered User
    Join Date
    05-06-2012
    Location
    Lisbon,Portugal
    MS-Off Ver
    Excel 2010
    Posts
    79

    How to transfer data from worksheet to vba userform

    Hi!
    I use a UserForm for imput data in worksheet, and the question is: How can I do the opposite?
    For exemple: I fill up data of sells in userform, and at same time, I should like that the useform gives me, through a textbox, the value of product of all sells?
    How could I do that?
    Thanks advence

  2. #2
    Valued Forum Contributor
    Join Date
    03-16-2012
    Location
    Aarhus, Denmark
    MS-Off Ver
    Excel 2007
    Posts
    992

    Re: How to transfer data from worksheet to vba userform

    The following fills the textbox txtTemp with the contents of A1 in sheet1 upon opening the userform:

    Please Login or Register  to view this content.
    Sincerely
    S?ren Larsen

    "Give a man a fish, and you'll feed him for a day. Give a man a fishing rod, and he'll steal your yacht!"

  3. #3
    Registered User
    Join Date
    05-06-2012
    Location
    Lisbon,Portugal
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: How to transfer data from worksheet to vba userform

    hi
    thank you for your quicly answer, but..
    I have a userform with multipage. In pag1, I fill out data that goes to the worksheet.In pag2 I have two comboboxs(Months and Selles), to chose two situations, and one textbox for appear the resolts of each seller in a particulary month. This values cames from worksheets by "Sumif function"and goes to "sheet1".
    In code above that I use, it gives me only (March). Something is not correct. could you help me? Thank you
    Private Sub cboseller2_change()


    If CboMonth2.Value = "January" Then
    TxtValT = WorksheetFunction.SumIf(Sheets("sheet1").Range("A:A"), CboSeller2, Sheets("Sheet1").Range("B:B"))
    ElseIf CboMonth2.Value = "February" Then
    TxtValT = WorksheetFunction.SumIf(Sheets("sheet1").Range("A:A"), CboSeller2, Sheets("Sheet1").Range("C:C"))
    Else
    TxtValT = WorksheetFunction.SumIf(Sheets("sheet1").Range("A:A"), CboSeller2, Sheets("Sheet1").Range("D:D"))
    End If

    End Sub

  4. #4
    Valued Forum Contributor
    Join Date
    03-16-2012
    Location
    Aarhus, Denmark
    MS-Off Ver
    Excel 2007
    Posts
    992

    Re: How to transfer data from worksheet to vba userform

    Could you place code tags around the code in your post? It makes it easier to read.

  5. #5
    Valued Forum Contributor
    Join Date
    03-16-2012
    Location
    Aarhus, Denmark
    MS-Off Ver
    Excel 2007
    Posts
    992

    Re: How to transfer data from worksheet to vba userform

    Try this:

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    05-06-2012
    Location
    Lisbon,Portugal
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: How to transfer data from worksheet to vba userform

    here goes the attach
    car_sales5F.xlsm

  7. #7
    Valued Forum Contributor
    Join Date
    03-16-2012
    Location
    Aarhus, Denmark
    MS-Off Ver
    Excel 2007
    Posts
    992

    Re: How to transfer data from worksheet to vba userform

    It's case-sensitive, which is why it does not work (it evaluates both logical tests as FALSE); this should work:

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    05-06-2012
    Location
    Lisbon,Portugal
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: How to transfer data from worksheet to vba userform

    hi Soren Larsen
    Many thanks for this solution.
    It didn't work, because the Months isn't in capital letter as sheets's name.(Very estrange isn't it?)
    Bye, and thank again
    Jdasp

  9. #9
    Valued Forum Contributor
    Join Date
    03-16-2012
    Location
    Aarhus, Denmark
    MS-Off Ver
    Excel 2007
    Posts
    992

    Re: How to transfer data from worksheet to vba userform

    That's funny; it works when I use it in the attached file. The reason why you need capital letters for months is that in the Userform initialize you have:

    Please Login or Register  to view this content.
    Perhaps you can upload a new file, where you've changed the code as per post # 7?

  10. #10
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: How to transfer data from worksheet to vba userform

    You still need to add the Code tags. Try using UCase

    Please Login or Register  to view this content.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  11. #11
    Registered User
    Join Date
    05-06-2012
    Location
    Lisbon,Portugal
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: How to transfer data from worksheet to vba userform

    Hi again,Soren Larson
    It works perfectly, however there is a small detail that consists of the following:
    when I test Pag2 and call for example the month of January, and the seller choose, in the textbox, it will automatically gave me the corresponding value - OK.
    But if I change then the name of the month and let stay the seller, the value of the Textbox (Value)wouldn't change so it ceases to be correct. How to solve this detail?
    Thank you for your kind
    Jdasp

  12. #12
    Valued Forum Contributor
    Join Date
    03-16-2012
    Location
    Aarhus, Denmark
    MS-Off Ver
    Excel 2007
    Posts
    992

    Re: How to transfer data from worksheet to vba userform

    You need to add code to the change-event of CboMonth2, just as you have in the change-event of cboseller2

  13. #13
    Registered User
    Join Date
    05-06-2012
    Location
    Lisbon,Portugal
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: How to transfer data from worksheet to vba userform

    hi Roy
    Thank you for your intervention.
    Please could you explain me the reason why must I use the code that you send me (Set Num....)?
    And what you mean with (UCase) in that code?
    Sorry I'm not expert in VBA perhaps candidate to be beginner
    Thanks in advance
    Jdasp

  14. #14
    Registered User
    Join Date
    05-06-2012
    Location
    Lisbon,Portugal
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: How to transfer data from worksheet to vba userform

    Hi Soren Larsen
    Thank you for all
    I already did that but it stay in same situation.

    Private Sub CboMonth2_Change()

    If CboSeller2.Value = "Jim" Then
    TxtValT.Value = WorksheetFunction.SumIf(Sheets("sheet1").Range("A:A"), CboMonth2.Value, Sheets("Sheet1").Range("B:B"))
    ElseIf CboSeller2.Value = "Rob" Then
    TxtValT.Value = WorksheetFunction.SumIf(Sheets("sheet1").Range("A:A"), CboMonth2.Value, Sheets("Sheet1").Range("C:C"))
    Else
    TxtValT.Value = WorksheetFunction.SumIf(Sheets("sheet1").Range("A:A"), CboMonth2.Value, Sheets("Sheet1").Range("D:D"))
    End If

    End Sub

  15. #15
    Valued Forum Contributor
    Join Date
    03-16-2012
    Location
    Aarhus, Denmark
    MS-Off Ver
    Excel 2007
    Posts
    992

    Re: How to transfer data from worksheet to vba userform

    Could you please place code tags around your code? It makes it a lot easier to read your code snippet! Read about code tags here:

    http://www.excelforum.com/misc.php?do=bbcode
    Last edited by Søren Larsen; 05-23-2012 at 01:00 PM.

  16. #16
    Valued Forum Contributor
    Join Date
    03-16-2012
    Location
    Aarhus, Denmark
    MS-Off Ver
    Excel 2007
    Posts
    992

    Re: How to transfer data from worksheet to vba userform

    You ranges are off, which is probaby why it does not work. Try this, untested, code instead:

    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    05-06-2012
    Location
    Lisbon,Portugal
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: How to transfer data from worksheet to vba userform

    [QUOTE=Søren Larsen;2799458]Could you please place code tags around your code? It makes it a lot easier to read your code snippet! Read about code tags here:

    [URL="http://www.excelforum.com/misc.php?do=bbcode"]' Transfer data from worksheet to userform boxes
    Private Sub cboseller2_change()

    If CboMonth2.Value = "JANUARY" Then
    TxtValT.Value = WorksheetFunction.SumIf(Sheets("sheet1").Range("A:A"), CboSeller2.Value, Sheets("Sheet1").Range("B:B"))
    ElseIf CboMonth2.Value = "FEBRUARY" Then
    TxtValT.Value = WorksheetFunction.SumIf(Sheets("sheet1").Range("A:A"), CboSeller2.Value, Sheets("Sheet1").Range("C:C"))
    Else
    TxtValT.Value = WorksheetFunction.SumIf(Sheets("sheet1").Range("A:A"), CboSeller2.Value, Sheets("Sheet1").Range("D:D"))
    End If

    End Sub

    ' Transfer data from worksheet to userform boxes
    Private Sub CboMonth2_Change()

    If CboSeller2.Value = "Jim" Then
    TxtValT.Value = WorksheetFunction.SumIf(Sheets("sheet1").Range("A:A"), CboMonth2.Value, Sheets("Sheet1").Range("B:B"))
    ElseIf CboSeller2.Value = "Rob" Then
    TxtValT.Value = WorksheetFunction.SumIf(Sheets("sheet1").Range("A:A"), CboMonth2.Value, Sheets("Sheet1").Range("C:C"))
    Else
    TxtValT.Value = WorksheetFunction.SumIf(Sheets("sheet1").Range("A:A"), CboMonth2.Value, Sheets("Sheet1").Range("D:D"))
    End If

    End Sub

  18. #18
    Registered User
    Join Date
    05-06-2012
    Location
    Lisbon,Portugal
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: How to transfer data from worksheet to vba userform

    Quote Originally Posted by Søren Larsen View Post
    You ranges are off, which is probaby why it does not work. Try this, untested, code instead:

    Please Login or Register  to view this content.
    ' Transfer data from worksheet to userform boxes
    Private Sub cboseller2_change()

    If CboMonth2.Value = "JANUARY" Then
    TxtValT.Value = WorksheetFunction.SumIf(Sheets("sheet1").Range("A:A"), CboSeller2.Value, Sheets("Sheet1").Range("B:B"))
    ElseIf CboMonth2.Value = "FEBRUARY" Then
    TxtValT.Value = WorksheetFunction.SumIf(Sheets("sheet1").Range("A:A"), CboSeller2.Value, Sheets("Sheet1").Range("C:C"))
    Else
    TxtValT.Value = WorksheetFunction.SumIf(Sheets("sheet1").Range("A:A"), CboSeller2.Value, Sheets("Sheet1").Range("D:D"))
    End If

    End Sub

    ' Transfer data from worksheet to userform boxes
    Private Sub CboMonth2_Change()

    If CboSeller2.Value = "Jim" Then
    TxtValT.Value = WorksheetFunction.SumIf(Sheets("sheet1").Range("A:A"), CboMonth2.Value, Sheets("Sheet1").Range("B:B"))
    ElseIf CboSeller2.Value = "Rob" Then
    TxtValT.Value = WorksheetFunction.SumIf(Sheets("sheet1").Range("A:A"), CboMonth2.Value, Sheets("Sheet1").Range("C:C"))
    Else
    TxtValT.Value = WorksheetFunction.SumIf(Sheets("sheet1").Range("A:A"), CboMonth2.Value, Sheets("Sheet1").Range("D:D"))
    End If

    End Sub

  19. #19
    Registered User
    Join Date
    05-06-2012
    Location
    Lisbon,Portugal
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: How to transfer data from worksheet to vba userform

    Hi Soren Larsen
    It was a big maratona, I realy appreciate your kindness
    All Works well
    Many thanks
    Jdasp

  20. #20
    Valued Forum Contributor
    Join Date
    03-16-2012
    Location
    Aarhus, Denmark
    MS-Off Ver
    Excel 2007
    Posts
    992

    Re: How to transfer data from worksheet to vba userform

    You're welcome!

  21. #21
    Registered User
    Join Date
    05-06-2012
    Location
    Lisbon,Portugal
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: How to transfer data from worksheet to vba userform

    hi Soren Larsen
    I have learned a lot with the Forums, it is cool to have already the solution to the exposed problem . The example I tried to solve, is the base to use in the procedures to be taken in similar situations. Because the solution was arranged somewhat strange, not wanting to abuse your patience I would like to know the technical reasons for that change (identifying the cell of the worksheet by number) as well as when you says "range off" what is it means? should be necessary to declare any variable (Dim. ..)? Thanks in advance to clarify that with anything you can forward saying.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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