Remove data from log on cancellation

Drawleeh

New Member
Joined
Sep 2, 2021
Messages
34
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
I have some code that colours in a row of information and then stores the date and the user that coloured in said row of information on a log.

That is all well and good but I would like to somehow figure out how to reverse said process. Currently if you use the code again on the same selection the colour changes back to 'no fill' but unfortunately I'm not sure how to remove that same information that was sent to the log initially. Any ideas?

VBA Code:
Sub CompleteLine()
Dim RCount As Integer
Dim SheetName As String

SheetName = ActiveSheet.Name

RCount = Selection.Columns.Count

If Selection.Interior.Color = 5296274 Then
Selection.Interior.ColorIndex = 0

Else

If RCount = 16384 And Selection.Interior.Color <> 5296274 Then
Selection.Interior.Color = 5296274
    With Sheets("Log")
    .Cells(1, 1).End(xlDown).Offset(1) = Format(Date, "dd/mm/yyyy")
    .Cells(1, 2).End(xlDown).Offset(1) = Environ("Username")
    .Cells(1, 2).End(xlDown).Offset(0, 1) = ActiveSheet.Name

    
End With
End If
End If
End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Not tested.

VBA Code:
Sub CompleteLine()
    Dim RCount As Integer
    Dim SheetName As String
    Dim LogEntryID As String, LogSearchRange As Range, R As Range

    SheetName = ActiveSheet.Name
    RCount = Selection.Columns.Count

    LogEntryID = SheetName & "!" & Selection.Address(False, False)

    If Selection.Interior.Color = 5296274 Then
        Selection.Interior.ColorIndex = 0

        With Worksheets("Log")
            Set LogSearchRange = Application.Intersect(.UsedRange, .Columns(4))
            Set R = LogSearchRange.Find(What:=LogEntryID, LookAt:=xlWhole)
            If Not R Is Nothing Then
                R.EntireRow.Delete Shift:=xlUp
            End If
        End With
    Else
        If RCount = 16384 And Selection.Interior.Color <> 5296274 Then
            Selection.Interior.Color = 5296274
            With Sheets("Log")
                .Cells(1, 1).End(xlDown).Offset(1).Value = Format(Date, "dd/mm/yyyy")
                .Cells(1, 2).End(xlDown).Offset(1) = Environ("Username")
                .Cells(1, 2).End(xlDown).Offset(0, 1) = ActiveSheet.Name
                .Cells(1, 2).End(xlDown).Offset(0, 2) = LogEntryID
            End With
        End If
    End If
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,593
Messages
6,120,435
Members
448,962
Latest member
Fenes

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top