Results 1 to 16 of 16

Thread: Using VB Forms With Excel

  1. #1
    Junior Member
    Join Date
    Mar 03
    Posts
    17

    Using VB Forms With Excel

    Im doing a project for my IT class, its a spreadsheet to keep track of scores for a sporting event. What I want todo is have a VB userform display and then from that you can enter contestant data and event data.

    But what im stuck on is how to move data say a name of a contestant from a textbox onto the spreadsheet? anyone got any ideas?

  2. #2
    Conquistador
    Join Date
    Dec 99
    Location
    Australia
    Posts
    4,527
    In VBA or VB?

  3. #3
    Junior Member
    Join Date
    Mar 03
    Posts
    17
    VB I think

  4. #4
    Evil Genius alex_read's Avatar
    Join Date
    May 00
    Location
    Espoo, Finland
    Posts
    5,482
    By Userform he's talking about the vb forms within Excel, so it'd be VBA there...

    Okay, shove a textbox & a command button on a form, then add this code & run it. This'll add whatever's typed in the textbox into the first sheet in the active workbook, in the first cell 'A1':
    Code:
    Private Sub CommandButton1_Click()
        Worksheets(1).Range("A1").Value = TextBox1.Text
    End Sub
    Last edited by alex_read; Mar 10th, 2003 at 06:27 AM.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  5. #5
    Conquistador
    Join Date
    Dec 99
    Location
    Australia
    Posts
    4,527
    I think you'd have to use .FormulaR1C1 though...

    Value gives some dodgy stuff etc

  6. #6
    Junior Member
    Join Date
    Mar 03
    Posts
    17
    Originally posted by alex_read
    By Userform he's talking about the vb forms within Excel, so it'd be VBA there...

    Okay, shove a textbox & a command button on a form, then add this code & run it. This'll add whatever's typed in the textbox into the first sheet in the active workbook, in the first cell 'A1':
    Code:
    Private Sub CommandButton1_Click()
        Worksheets(1).Range("A1").Value = TextBox1.Text
    End Sub
    Thanks, that worked ill let you know if I have any more problems.

  7. #7
    Evil Genius alex_read's Avatar
    Join Date
    May 00
    Location
    Espoo, Finland
    Posts
    5,482
    Thanks, that worked ill let you know if I have any more problems.
    uh, gee thanks - um, guess I'll look forward to it!

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  8. #8
    Junior Member
    Join Date
    Mar 03
    Posts
    17
    Ok, new problem ive got some check boxes which when clicked enters a contestant for a event. The problem is when I unclick them they are entered again?

  9. #9
    Evil Genius alex_read's Avatar
    Join Date
    May 00
    Location
    Espoo, Finland
    Posts
    5,482
    It's usually best to start another post if there's a different question subject matter - even if it's from the same project, you'll have more replies this way

    Ok, new problem ive got some check boxes which when clicked enters a contestant for a event. The problem is when I unclick them they are entered again?
    I take it you're performing the code to enter a contestant within the Checkbox_Click() event? If this is the case, the click event is triggered when the user clicks on the checkbox - whether they tick the box or remove the tick, so you might want to put something like this in:
    Code:
    Private Sub CheckBoxNameHere_Click()
        If CheckBoxNameHere.value = 1 Then '(true/ticked)
            'Execute the enter contestant bit here
        End If
    End Sub

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  10. #10
    Junior Member
    Join Date
    Mar 03
    Posts
    17
    Ok heres what ive got and it doesn't work

    Code:
    Private Sub CheckBox1_Click()
    If CheckBox1.Value = 1 Then '(true/ticked)
                Selection.EntireRow.Insert
    Worksheets(3).Range("A2").Value = txtid.Text
    Worksheets(3).Range("B2").Value = txtfirstname.Text
        End If
    End Sub

  11. #11
    Evil Genius alex_read's Avatar
    Join Date
    May 00
    Location
    Espoo, Finland
    Posts
    5,482
    Does it throw up an error message?

    Does changing the top line to this make a difference?

    Code:
    If CheckBox1.Value <> 0 Then

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  12. #12
    Junior Member
    Join Date
    Mar 03
    Posts
    17
    Nope, that doesn't help I don't get a error message I just select the check box and nothing happens.

  13. #13
    Junior Member
    Join Date
    Mar 03
    Posts
    17
    Ok, ive kinda got it working ive used this code,

    Private Sub CheckBox1_Click()
    If CheckBox1.Value = 0 Then
    Selection.EntireRow.Insert
    Worksheets(3).Range("A2").Value = txtid.Text
    Worksheets(3).Range("B2").Value = txtfirstname.Text
    End If
    End Sub

    It works but only if I select then unselect, hopefully you can tell me whats wrong from that.

  14. #14
    Evil Genius alex_read's Avatar
    Join Date
    May 00
    Location
    Espoo, Finland
    Posts
    5,482
    huh, weird, what about using this one then:

    Code:
    Private Sub Check1_Click()
        If Check1.Value = vbChecked Then
            MsgBox "Checkbox is ticked"
        Else
            MsgBox "Checkbox Not ticked"
        End If
    End Sub

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  15. #15
    Junior Member
    Join Date
    Mar 03
    Posts
    17
    That code works but its backwards, when the tick box is not ticked it says it is?

  16. #16
    Junior Member
    Join Date
    Mar 03
    Posts
    17
    Don't worry ive got it to work now

Posting Permissions

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