• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Update my existing macro to be able to update and delete

troy79

New Member
Hi.

I have a VBA macro that I have been using to update a roster with planned and unplanned leave.

What I was hoping to do was to have the ability within the same code or a separate code to:
- Delete requests that are no longer required
or
- Change the type of planned or unplanned leave

Here is the script that I use to add planned and unplanned leave, any help in making the above changes I would really appreciate.


>>> use code - tags <<<
Code:
Private Sub cbbAdd_Click()

answer = MsgBox("Are you sure you want make the changes?", vbYesNo + vbQuestion, "Add Record")
If answer = vbYes Then

Dim LeaveDate As Date
LeaveDate = txtLeaveStart.Text
Dim LeaveEnd As Date
LeaveEnd = txtLeaveEnd.Text
Dim FirstName As String
FirstName = FirstNameCombo.Text
Dim LeaveType As String
LeaveType = LeaveTypeCombo.Text
Dim DateAdded As Date
Dim wsh As Worksheet
Set wsh = ThisWorkbook.Worksheets("Leave")
Set tbl = wsh.ListObjects("tblEmployees")
Dim lRow As ListRow
For LeaveDate = CDate(txtLeaveStart.Text) To CDate(txtLeaveEnd.Text)

Set lRow = tbl.ListRows.Add
With lRow
.Range(1) = LeaveDate
.Range(2) = FirstName
.Range(3) = LeaveType
.Range(5) = Now()

End With
Next
End If

MsgBox "Complete"

End Sub
 
Last edited by a moderator:
There's a lot of necessary information missing here. The big one is what criteria you might use to identify rows that are no longer required.

I don't think you'd do it in this same program, though. The way I understand your description, you want a program that runs down all the rows in a worksheet and identifies some for deletion. This program merely transfers text from (I suppose) an input dialogue to a new row on the worksheet. And changing the leave type will require some discussion too.
 
Back
Top