Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I'm trying to create a simple useform on excel. I want to select the worksheet into which the data is entered based on the value selected from a combobox list. In this case it is a list of athlete's name ('cboAthlete.value). If 'Bob Smith' is selected then the worksheet selected would be 'Bob Smith' and all the data inputed there.
Below is the code. I am a complete novice and appreciate that this is probably very simple but would be grateful for any help. Thanks
Private Sub cmdAdd_Click()Dim iRow As Long
Dim iPart As Long
Dim ws As Worksheet
Set ws = Worksheets("MaxJumps")'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).RowiPart = Me.cboAthlete.ListIndex
'check for a part number
If Trim(Me.cboAthlete.Value) = "" Then
Me.cboAthlete.SetFocus
MsgBox "Please enter your full name"
Exit Sub
End If'copy the data to the database
ws.Cells(iRow, 1).Value = Me.cboAthlete.Value
ws.Cells(iRow, 2).Value = Me.txtDate.Value
ws.Cells(iRow, 3).Value = Me.txtWeight.Value
ws.Cells(iRow, 4).Value = Me.txtCMJ.Value
ws.Cells(iRow, 5).Value = Me.txtSJ.Value
ws.Cells(iRow, 6).Value = Me.txtDJ.Value
ws.Cells(iRow, 7).Value = Me.txtContact.Value'clear the data
Me.cboAthlete.Value = ""
Me.txtDate.Value = Format(Date)
Me.txtWeight.Value = ""
Me.txtCMJ.Value = ""
Me.txtSJ.Value = ""
Me.txtDJ.Value = ""
Me.txtContact.Value = ""
Me.cboAthlete.SetFocusEnd Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()Dim cAthlete As Range
Dim ws As Worksheet
Set ws = Worksheets("AthleteList")For Each cAthlete In ws.Range("AthleteList")
With Me.cboAthlete
.AddItem cAthlete.Value
.List(.ListCount - 1, 1) = cAthlete.Offset(0, 1).Value
End With
Next cAthleteMe.txtDate.Value = Format(Date)
Me.txtWeight.Value = ""
Me.txtCMJ.Value = ""
Me.txtSJ.Value = ""
Me.txtDJ.Value = ""
Me.txtContact.Value = ""
Me.cboAthlete.SetFocusEnd Sub
Private Sub UserForm_QueryClose(Cancel As Integer, _
CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "Please use 'Close' button!"
End If
End Sub

![]() |
compile error in hidden m...
|
macro code to import tex...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |