DJMXM
New Member
- Joined
- Jun 19, 2013
- Messages
- 45
Hello Once Again.... I am posting my code below. I have a UserForm (Add New Employee).... Here are the parameters:
TextBox1 - Employee Name
ComboBox1 - Job Title
ComboBox2 - Salary or Hourly (This is the first box that determines what happens next)
ComboBox3 - Yearly Or Weekly
TextBox2 - Annual Salary
TextBox3 - Weekly Salary
TextBox4 - Hourly Wage
Ok - Here is what I need -
When ComboBox2 (Salary/Hourly) is "Hourly" I only need TextBox4 = True
When ComboBox2 (Salary/Hourly) is "Salary" I need TextBox4=False and ComboBox3 = True
When ComboBox3 (Yearly/Weekly) is "Yearly" TextBox2 = True and TextBox3 = False
When ComboBox3 (Yearly/Weekly) is "Weekly" TextBox2 = False and TextBox3 = True
Basically
Employee Name > Job > (IF) Salary > (Ask) ComboBox3 > Yearly > TextBox2 > ClickButton1
Employee Name > Job > (IF) Salary > (Ask) ComboBox3 > Weekly > TextBox3 > ClickButton1
Employee Name > Job > (IF) Text > TextBox4 > ClickButton1
I Hope I am making Sense..... BTW There is a ton of extra code with this User From that is for sorting and placement!
Thank You in Advance!!!
Mike
TextBox1 - Employee Name
ComboBox1 - Job Title
ComboBox2 - Salary or Hourly (This is the first box that determines what happens next)
ComboBox3 - Yearly Or Weekly
TextBox2 - Annual Salary
TextBox3 - Weekly Salary
TextBox4 - Hourly Wage
Ok - Here is what I need -
When ComboBox2 (Salary/Hourly) is "Hourly" I only need TextBox4 = True
When ComboBox2 (Salary/Hourly) is "Salary" I need TextBox4=False and ComboBox3 = True
When ComboBox3 (Yearly/Weekly) is "Yearly" TextBox2 = True and TextBox3 = False
When ComboBox3 (Yearly/Weekly) is "Weekly" TextBox2 = False and TextBox3 = True
Basically
Employee Name > Job > (IF) Salary > (Ask) ComboBox3 > Yearly > TextBox2 > ClickButton1
Employee Name > Job > (IF) Salary > (Ask) ComboBox3 > Weekly > TextBox3 > ClickButton1
Employee Name > Job > (IF) Text > TextBox4 > ClickButton1
I Hope I am making Sense..... BTW There is a ton of extra code with this User From that is for sorting and placement!
Thank You in Advance!!!
Mike
Code:
Private Sub UserForm_Initialize()
Me.ComboBox1.List = Worksheets("Start Here Sheet").Range("AP55:AP67").Value
Me.ComboBox2.List = Worksheets("Start Here Sheet").Range("AP70:AP71").Value
Me.ComboBox3.List = Worksheets("Start Here Sheet").Range("AP73:AP74").Value
End Sub
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If TextBox2 = vbNullString Then Exit Sub
If IsNumeric(Me.TextBox2.Value) Then
Me.TextBox2.Value = Format(Me.TextBox2.Value, "Currency")
End If
End Sub
Private Sub TextBox3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If TextBox3 = vbNullString Then Exit Sub
If IsNumeric(Me.TextBox3.Value) Then
Me.TextBox3.Value = Format(Me.TextBox3.Value, "Currency")
End If
End Sub
Private Sub TextBox4_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If TextBox4 = vbNullString Then Exit Sub
If IsNumeric(Me.TextBox4.Value) Then
Me.TextBox4.Value = Format(Me.TextBox4.Value, "Currency")
End If
End Sub
Private Sub CommandButton1_Click()
Sheets("Start Here Sheet").Range("N177").Value = TextBox1.Text
Sheets("Start Here Sheet").Range("O177").Value = ComboBox1.Value
Sheets("Start Here Sheet").Range("P177").Value = ComboBox2.Value
Sheets("Start Here Sheet").Range("Q177").Value = ComboBox3.Value
Sheets("Start Here Sheet").Range("R177").Value = TextBox2.Text
Sheets("Start Here Sheet").Range("S177").Value = TextBox3.Text
Sheets("Start Here Sheet").Range("T177").Value = TextBox4.Text
' Sort Employee Names On Start Here Sheet
Application.ScreenUpdating = False
ActiveWorkbook.Worksheets("Start Here Sheet").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Start Here Sheet").Sort.SortFields.Add Key:=Range( _
"P6:P178"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Start Here Sheet").Sort.SortFields.Add Key:=Range( _
"O6:O178"), SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:= _
"Manager,Shift Manager,Chef,Sous Chef,Line Cook,Prep Cook,Dishwasher,Bartender,Server,****tail,Bus Boy,Doorman,Hostess" _
, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Start Here Sheet").Sort.SortFields.Add Key:=Range( _
"N6:N178"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Start Here Sheet").Sort
.SetRange Range("N6:T178")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
ActiveSheet.Range("N6").Select
' Update Employee Names to Monthly Cost Sheets
Application.ScreenUpdating = False
Dim bottomV As Integer
bottomV = Sheets("Start Here Sheet").Range("V" & Rows.Count).End(xlUp).Row
Dim bottomG As Integer
bottomG = Sheets("Monthly Costs").Range("G" & Rows.Count).End(xlUp).Row
Dim bottomK As Integer
bottomK = Sheets("Monthly Costs").Range("K" & Rows.Count).End(xlUp).Row
Dim bottomR As Integer
bottomR = Sheets("Monthly Costs").Range("R" & Rows.Count).End(xlUp).Row
Dim bottomI As Long
Dim rng1 As Range
Dim rng2 As Range
Sheets("Monthly Costs").Range("G4:I" & bottomG + 1).ClearContents
Sheets("Monthly Costs").Range("K4:M" & bottomK + 1).ClearContents
Sheets("Monthly Costs").Range("R4:T" & bottomR + 1).ClearContents
For Each rng1 In Sheets("Start Here Sheet").Range("V6:V" & bottomV)
Select Case rng1.Value
Case "1"
Sheets("Start Here Sheet").Range("N" & rng1.Row & ":O" & rng1.Row).Copy Sheets("Monthly Costs").Cells(Rows.Count, "G").End(xlUp).Offset(1, 0)
bottomI = Sheets("Monthly Costs").Range("I" & Rows.Count).End(xlUp).Row
For Each rng2 In Sheets("Monthly Costs").Range("I4:I" & bottomI)
If rng2 = "" Then
Sheets("Start Here Sheet").Range("U" & rng1.Row).Copy
Sheets("Monthly Costs").Range("I" & rng2.Row).PasteSpecial xlPasteValues
Exit For
End If
Next rng2
Case "5"
Sheets("Start Here Sheet").Range("N" & rng1.Row & ":O" & rng1.Row).Copy Sheets("Monthly Costs").Cells(Rows.Count, "K").End(xlUp).Offset(1, 0)
Sheets("Start Here Sheet").Range("U" & rng1.Row).Copy
Sheets("Monthly Costs").Cells(Rows.Count, "M").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Case "6"
Sheets("Start Here Sheet").Range("N" & rng1.Row & ":O" & rng1.Row).Copy Sheets("Monthly Costs").Cells(Rows.Count, "R").End(xlUp).Offset(1, 0)
Sheets("Start Here Sheet").Range("U" & rng1.Row).Copy
Sheets("Monthly Costs").Cells(Rows.Count, "T").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
End Select
Next rng1
Application.CutCopyMode = False
Application.ScreenUpdating = True
'Ask for aditional new staff member
MsgBox "One New Employee Added"
response = MsgBox("Do You Want To Add Another New Employee?", _
vbYesNo)
If response = vbYes Then
TextBox1.Text = ""
ComboBox1.Value = ""
ComboBox2.Value = ""
ComboBox3.Value = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox1.SetFocus
Else
Unload Me
End If
End Sub
Private Sub CommandButton2_Click()
End
End Sub