mardi 26 mai 2020

Change a value on another worksheet based on a checkbox check

After some searching and trying to figure it out my self i'm stumped. I could use some help on this one.

I have an excel workbook that has multiple tabs. The two I need help with is the "KronosEntries" and the "MASTER" tab. The MASTER tab has a list of all the missed days and vacation time for the employee. The KronosEntries tab has a list of all the records from the MASTER tab that need to be entered into Kronos. Once they are entered into Kronos I will check the box next to that line to remove it from the KronosEntries tab. When I add a new line on the MASTER tab it automatically adds a "No" in column R. What I want to happen is when I check the checkbox on the KronosEntries tab I want to change column R on the MASTER tab to "Yes" for the row that has the same data.

Here's the KronosEntries tab example.

KronosEntries

Here's the MASTER tab example.

MasterTab

Here's what I used to add the checkboxes.

Sub Addcheckboxes()

'Declare variables and data types
Dim cell, LRow As Single
Dim ChkBx As CheckBox
Dim CLeft, CTop, CHeight, CWidth As Double

'Don't refresh or update screen while processing macro, this will make the macro quicker.
Application.ScreenUpdating = False

'Find last non empty cell in column A
LRow = Worksheets("KronosEntries").Range("A" & Rows.Count).End(xlUp).Row

'Iterate through 2 to last non empty cell
For cell = 2 To LRow

    'Check if cell in column B is not equal to nothing
    If Cells(cell, "B").value <> "" And Cells(cell, "B").value <> "Employee ID" Then

        'Save cell dimensions and coordinates of corresponding cell in column E to variables
        CLeft = Cells(cell, "A").Left
        CTop = Cells(cell, "A").Top
        CHeight = Cells(cell, "A").Height
        CWidth = Cells(cell, "A").Width

        'Create checkbox based on dimension and coordinates data from variables
        Worksheets("KronosEntries").CheckBoxes.Add(CLeft, CTop, CWidth, CHeight).Select

        With Selection
            .Caption = ""
            .value = xlOff
            .LinkedCell = .TopLeftCell.Offset(0, 8).Address
            .Display3DShading = False
        End With

    End If

    Next cell

    Worksheets("KronosEntries").Range("A6").Select

    'Turn on screen refresh
    Application.ScreenUpdating = True

End Sub

Here's what I used to remove the checkboxes.

Sub RemoveCheckboxes()

    'Declare variables and data types
    Dim ChkBx As CheckBox

    'Iterate through all check boxes on active sheet
    For Each ChkBx In Worksheets("KronosEntries").CheckBoxes

        'Remove checkbox
        ChkBx.Delete

    'Continue with next checkbox
    Next

End Sub

The part I cant seem to sort out is the code to change column R to Yes for the row that has the same data. Can someone help? Thank you

Sub ChangeData
    ?
End Sub



Aucun commentaire:

Enregistrer un commentaire