michaeltsmith93
Board Regular
- Joined
- Sep 29, 2016
- Messages
- 83
Hi,
I've created my first userform, and there's something wrong, but I'm not sure what. Please let me know if you need more info than the code that's here.
Here is everything in my VBA Editor. I'd also appreciate it if someone could tell me how to put a box of code in here rather than plain text.
Private Sub CommandButton1_Click()
End Sub
Private Sub Cancel_Click()
Unload Me
End Sub
Private Sub Label3_Click()
End Sub
Private Sub Name_Change()
End Sub
Private Sub OOK_Click()
End Sub
Private Sub OK_Click()
Dim ERow As Long
Dim ws As Worksheet
Set ws = Worksheets("PartsData")
'find first empty row
ERow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
'check for input
If Trim(Me.Name.Value) Or Trim(Me.StudyRole.Value) Or Trim(Me.MatrixRole.Value) Or Trim(Me.Department.Value) = "" Then
MsgBox "Please fill all fields."
Exit Sub
End If
With ws
.Cells(ERow, 1).Value = Me.Name.Value
.Cells(ERow, 2).Value = Me.StudyRole.Value
.Cells(ERow, 4).Value = Me.MatrixRole.Value
.Cells(ERow, 5).Value = Me.Department.Value
End With
Me.Name.Value = ""
Me.StudyRole.Value = ""
Me.MatrixRole.Value = ""
Me.Department.Value = ""
End Sub
Private Sub UserForm_Click()
End Sub
Private Sub UserForm_Initialize()
Dim MRole As Range
Dim Dept As Range
For Each MRole In Range("MatrixRoles")
With Me.MatrixRole
.AddItem MRole.Value
End With
Next MRole
For Each Dept In Range("Depts")
With Me.Department
.AddItem Dept.Value
End With
Next Dept
End Sub
I've created my first userform, and there's something wrong, but I'm not sure what. Please let me know if you need more info than the code that's here.
Here is everything in my VBA Editor. I'd also appreciate it if someone could tell me how to put a box of code in here rather than plain text.
Private Sub CommandButton1_Click()
End Sub
Private Sub Cancel_Click()
Unload Me
End Sub
Private Sub Label3_Click()
End Sub
Private Sub Name_Change()
End Sub
Private Sub OOK_Click()
End Sub
Private Sub OK_Click()
Dim ERow As Long
Dim ws As Worksheet
Set ws = Worksheets("PartsData")
'find first empty row
ERow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
'check for input
If Trim(Me.Name.Value) Or Trim(Me.StudyRole.Value) Or Trim(Me.MatrixRole.Value) Or Trim(Me.Department.Value) = "" Then
MsgBox "Please fill all fields."
Exit Sub
End If
With ws
.Cells(ERow, 1).Value = Me.Name.Value
.Cells(ERow, 2).Value = Me.StudyRole.Value
.Cells(ERow, 4).Value = Me.MatrixRole.Value
.Cells(ERow, 5).Value = Me.Department.Value
End With
Me.Name.Value = ""
Me.StudyRole.Value = ""
Me.MatrixRole.Value = ""
Me.Department.Value = ""
End Sub
Private Sub UserForm_Click()
End Sub
Private Sub UserForm_Initialize()
Dim MRole As Range
Dim Dept As Range
For Each MRole In Range("MatrixRoles")
With Me.MatrixRole
.AddItem MRole.Value
End With
Next MRole
For Each Dept In Range("Depts")
With Me.Department
.AddItem Dept.Value
End With
Next Dept
End Sub