PDA

View Full Version : Update my existing macro to be able to update and delete



troy0111
10-08-2022, 03:58 PM
Hi.

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

I have it cross posted here: https://chandoo.org/forum/threads/update-my-existing-macro-to-be-able-to-update-and-delete.49277/

https://chandoo.org/forum/threads/update-my-existing-macro-to-be-able-to-update-and-delete.49277/


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.



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

DocAElstein
10-09-2022, 03:01 PM
Hello troy0111
Welcome to ExcelFox , and thanks for adding the link to where you also posted. (By the way, in case you are new to forums, that is known as "cross posting", and it is important to give links, just as you did, to all places where you post the same question, because many forums have a rule insisting on that.)

It might be a lot easier for someone trying to help if you could upload a sample file, but please keep the data on it to the minimum necessary to show all scenarios, and also desensitise any personal data.

It is often also most useful to have two files , or two worksheets, one as the "Before" representing what you initially have, and then the other , the "After" to show what you want done, and please include very clear details about how/ why / what was done to take us from the "Before" to the "After"
Bear in mind that it will be obvious to you what you want, and almost any short description will sound fully understandable to you, but for someone seeing your requirement for the first time will need a very clear detailed walk - through/ step by step explanation of what you want


Alan