ianfrancis56
New Member
- Joined
- Aug 10, 2011
- Messages
- 34
All,
I'm a little stumped here....I am either missing it in posts and tutorials or I haven't see it. I have a range in Sheets("Labor") where the user enters the quantity and days. I know a Worksheet Change Event can't be activated by a cell with a formula in it, so that's why I am focusing on these since they are user entered. Basically I want any time a quantity and days entry or deletion occurs to trigger the below VBA.
I'm a little stumped here....I am either missing it in posts and tutorials or I haven't see it. I have a range in Sheets("Labor") where the user enters the quantity and days. I know a Worksheet Change Event can't be activated by a cell with a formula in it, so that's why I am focusing on these since they are user entered. Basically I want any time a quantity and days entry or deletion occurs to trigger the below VBA.
Code:
Sub PEOFTECalc_Click()
Application.ScreenUpdating = False
Dim i@, lin@, LabCatCt@, LabCt@, PEOCt@, FirstRw@, LastRw@
lin = 13
PEOCt = ActiveSheet.Range("G" & Rows.Count).End(xlUp).Row
Lab = Sheets("Labor").Range("G5:M35")
LabCt = 0
With Sheets("PEO-EIS FTE Calculation")
If .Cells(lin, "G") <> "" Then
For i = lin To .Cells(lin, "G").End(xlDown).Row
.Cells(i, "G").EntireRow.ClearContents
Next i
End If
FirstRw = Sheets("Labor").UsedRange.Cells(5, "G").Row
LastRw = Sheets("Labor").Cells(5, "G").End(xlDown).Row
For i = FirstRw To LastRw Step 1
If Sheets("Labor").Cells(i, "Q").Value <> "" Then
.Rows(lin).EntireRow.Insert
.Cells(lin, "G") = Sheets("Labor").Cells(i, "G")
.Cells(lin, "I") = .Application.VLookup(.Cells(lin, "G"), Lab, 4)
.Cells(lin, "H") = .Application.VLookup(.Cells(lin, "G"), Lab, 7)
.Cells(lin, "J") = .Cells(lin, "H") * .Cells(lin, "I")
lin = lin + 1
LabCt = LabCt + 1
End If
Next i
FirstRw = .UsedRange.Cells(13 + LabCt, "G").Row
LastRw = .UsedRange.Rows(.UsedRange.Rows.Count).Row
For i = LastRw To FirstRw Step -1
With Cells(i, "G")
If .Value = "" Then
.EntireRow.Delete xlShiftDown
End If
End With
Next i
.Rows(LabCt + 13).EntireRow.Insert
.Rows(LabCt + 15).EntireRow.Insert
.Range("G13:G" & Rows.End(xlDown).Row).Rows.AutoFit
.Rows(LabCt + 13).RowHeight = 3.75
.Rows(LabCt + 15).RowHeight = 3.75
.Cells(LabCt + 14, "H") = Application.Sum(.Range("H13:H" & LabCt + 13))
.Cells(LabCt + 14, "J") = Application.Sum(.Range("J13:J" & LabCt + 13))
.Cells(LabCt + 17, "J") = .Cells(LabCt + 14, "H") / .Cells(LabCt + 16, "H")
End With
End Sub
['/CODE]
Thanks!