Heeellpp

trfootballcoach

New Member
Joined
Sep 24, 2011
Messages
5
Ok i am a new to Excel and VBL. So far what i have is a user form that the user will input text in. data entered are Last Name(text box), First Name (text box) , Date (text box) , Male(option box) and Female (option box). What i am trying to do is have all the info for a male be entered onto worksheet 1 and data for a female to be entered on to worksheet two. Any Ideas for the code?
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
I'm assuming you have a command button that submits the data when clicked...

Then try a version of this. You might need to tweak the ranges and sheet names a bit...

Code:
Sub CommandButton1_Click()
If OptionButtonMale.Value = True Then
    Sheets("Sheet1").Range("A1") = TextBoxLast.value
    Sheets("Sheet1").Range("A2") = TextBoxFirst.value
    Sheets("Sheet1").Range("A3") = TextBoxDate.value
Else
    Sheets("Sheet2").Range("A1") = TextBoxLast.value
    Sheets("Sheet2").Range("A2") = TextBoxFirst.value
    Sheets("Sheet2").Range("A3") = TextBoxDate.value
End If
End Sub

Is this what you needed?
 
Upvote 0
thank you for the reply and it does look like it will work but i must be missing something here is everything i have



Private Sub cmdadd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets ("males" , "females")

'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row

'check for a Name
If Trim(Me.txtnamelast.Value) = "" Then
Me.txtnamelast.SetFocus
MsgBox "Please enter a Student Name"
End If

If Trim(Me.txtname1st.Value) = "" Then
Me.txtname1st.SetFocus
MsgBox "Please enter a Student Name"
End If

If Trim(Me.txtteacher.Value) = "" Then
Me.txtteacher.SetFocus
MsgBox "Please enter Teacher"
End If

If Trim(Me.txtdate.Value) = "" Then
Me.txtdate.SetFocus
MsgBox "Please enter a Date"
Exit Sub
End If

If OptionButtonmale.Value = True Then
Sheets("male").Cells(iRow, 1).Value = txtnamelast.Value
Sheets("male").Cells(iRow, 2).Value = txtname1st.Value
Sheets("male").Cells(iRow, 3).Value = txtdate.Value
Sheets("male").Cells(iRow, 4).Value = txtstarttime.Value
Sheets("male").Cells(iRow, 5).Value = txtendtime.Value

Else
Sheets("female").Cells(iRow, 1).Value = txtnamelast.Value
Sheets("female").Cells(iRow, 2).Value = txtname1st.Value
Sheets("female").Cells(iRow, 3).Value = txtdate.Value
Sheets("female").Cells(iRow, 4).Value = txtstarttime.Value
Sheets("female").Cells(iRow, 5).Value = txtendtime.Value
End If



Cells(iRow, 1) = WorksheetFunction.Proper(txtnamelast)
Cells(iRow, 2) = WorksheetFunction.Proper(txtname1st)
Cells(iRow, 4) = WorksheetFunction.Proper(txtteacher)


'clear the data
Me.txtname1st.Value = ""
Me.txtteacher.Value = ""
Me.txtnamelast.Value = ""
Me.txtdate.Value = ""
Me.OptionButtonmale.Value = False
Me.OptionButtonfemale.Value = False
Me.txtnamelast.SetFocus





End Sub
 
Upvote 0
I'm not sure what your problem is...can you explain what error you are getting, or what you're not getting that you want?

Also, for future posts, please use the code tags (click the # when posting)
 
Upvote 0
I think there are a couple of places you could be erratic in your code. First of all, I'm not sure if it's possible, but when I tried it, it didn't work for me...I don't think your method of setting the worksheets is right. (See code below)

Code:
Dim ws As Worksheet
Set ws = Worksheets ("males" , "females")

I don't think you can dim ws as worksheet and then give it 2 worksheet names...also, I don't see the point of doing this and then later on, continue to use Sheets("male") and Sheets("female")...the reason for doing that at the beginning is to reduce the amount of characters needed to reference a sheet...also, if your method actually does work somehow, it won't work when you try to reference "male" and "female" when you have clearly defined the sheets to be "males" and "females" (both with an s) in the beginning...

With all that said, here is an example of something I got to work for me...very basic, but hopefully should get all of my previously stated points across:

Code:
Private Sub CommandButton1_Click()
    Dim wsm As Worksheet
    Set wsm = Worksheets("males")
    Dim wsf As Worksheet
    Set wsf = Worksheets("females")
    
    If OptionButtonMale.Value = True Then
        wsm.Range("A1").Value = txtLast.Value
        wsm.Range("A2").Value = txtFirst.Value
        wsm.Range("A3").Value = txtDate.Value
    Else
        wsf.Range("A1").Value = txtLast.Value
        wsf.Range("A2").Value = txtFirst.Value
        wsf.Range("A3").Value = txtDate.Value
    End If
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,773
Messages
6,126,821
Members
449,340
Latest member
hpm23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top