Conditionally adding data to list using VBA

skydive1981
06-30-2005, 04:39 AM
Hello all,

I have a query -

I am making a workbook to record my staff's overtime requests. What I want to do is add each request by clicking abutton and then filling in some info. I also want this button click to check another list for the requestors name. If the requestors name is NOT already in the list I want it to be added (this is to toal up each employee's overtime). I am stuck on the adding the the table bit! The code I am using up to now is below. Can anyone help me with what to do next?
Thanks

Private Sub butRequest1_Click()
Dim jlgName
Dim jlgDate As Date
Dim jlgJust As String
Dim jlgVerified
Dim jlgSubmitted
Dim jlgSetA As Range
Dim jlgCompany
Dim jlgHours As Integer

With ActiveSheet

jlgName = InputBox("Name of Agent:", "Agent", "")
jlgCompany = InputBox("Is the agent staff or agency?:")
jlgDate = InputBox("Enter date of overtime:", "Date", "")
jlgJust = InputBox("What is the agents justification?:", "Justification", "")
jlgHours = InputBox("How many hours?:", "Hours", "")

Set jlgSetA = Range("b14:b100").Find(what:="")
If jlgSetA Is Nothing Then MsgBox ("No Space")
jlgSetA = jlgDate
jlgSetA.Offset(columnOffset:=1) = jlgCompany
jlgSetA.Offset(columnOffset:=2) = jlgName
jlgSetA.Offset(columnOffset:=3) = jlgJust
jlgSetA.Offset(columnOffset:=4) = jlgHours

End With

End SubAdded vb tags. Click 'Reply' on this post if you want to see how they work, or read all about tags here (www.xtremevbtalk.com/misc.php?do=bbcode).
Also, indentation makes your code a lot easier to read.

skydive1981
06-30-2005, 06:46 AM
Ok, I haev managed to get around it with the following code.



Private Sub butRequest1_Click()
Dim jlgName
Dim jlgDate As Date
Dim jlgJust As String
Dim jlgVerified
Dim jlgSubmitted
Dim jlgSetA As Range
Dim jlgCompany
Dim jlgHours As Integer
Dim jlgFind
Dim jlgNew As Range

On Error Resume Next

With ActiveSheet

jlgName = InputBox("Name of Agent:", "Agent", "")
jlgCompany = InputBox("Is the agent staff or contractor?:")
jlgDate = InputBox("Enter date of overtime:", "Date", "")
jlgJust = InputBox("What is the agents justification?:", "Justification", "")
jlgHours = InputBox("How many hours?:", "Hours", "")

Set jlgSetA = Range("b14:b100").Find(what:="")
jlgSetA = jlgDate
jlgSetA.Offset(columnOffset:=1) = jlgCompany
jlgSetA.Offset(columnOffset:=2) = jlgName
jlgSetA.Offset(columnOffset:=3) = jlgJust
jlgSetA.Offset(columnOffset:=4) = jlgHours

Range("l8:l25").Select
jlgFind = Selection.Find(what:=jlgName)

If jlgFind = jlgName Then
MsgBox ("Done")
Else
Set jlgNew = Range("l8:l25").Find(what:="")
jlgNew = jlgName
MsgBox ("Done")
End If

End With

End Sub

What I now want to do is keep a running total of the individual employees overtime. I haev no idea how to do this!! Would I need to use VB or is there a formula I could use? Basically, everytime I add a new request it would need to check the name (jlgName) against the name in the table (originally entered as jlgNew). If they match, it would need to add the number of newly requested hours (jlgHours) to the current value in the table.

Again, thanks in advance!!

Lee

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum