Results 1 to 2 of 2

Thread: Update my existing macro to be able to update and delete

  1. #1
    Junior Member
    Join Date
    Oct 2022
    Posts
    1
    Rep Power
    0

    Update my existing macro to be able to update and delete

    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/up...-delete.49277/
    HTML Code:
    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.


    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 DocAElstein; 10-08-2022 at 05:15 PM. Reason: cross post link

  2. #2
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,455
    Rep Power
    10
    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
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

Similar Threads

  1. Macro to open and update several workbooks
    By Flupsie in forum Excel Help
    Replies: 0
    Last Post: 08-07-2014, 08:51 AM
  2. Replies: 4
    Last Post: 02-27-2014, 08:49 PM
  3. Replies: 2
    Last Post: 05-30-2013, 07:28 PM
  4. How to Update Daily Log In Another Sheet
    By Rajesh Kr Joshi in forum Excel Help
    Replies: 6
    Last Post: 04-06-2013, 01:47 PM
  5. Replies: 2
    Last Post: 11-17-2011, 07:49 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •