I would like to auto ClearContents for a cell based on another cell being blank.
I have the values in the "Tracker" sheet in column L, on which rely exactly the same rows in another sheet ("Formulas") in column AF.
When I remove manually the value from the cell L2 for example, I would like to auto Clear Contents for column AF2 and so on.
I found Clear Excel Cell if Value less than another Cell value
I tried the following:
Sub ClearLowerThan()
Dim c As Range, Rng As Range
Dim LastRow As Long
Dim ws As Worksheet, ws2 As Worksheet: Set ws = Sheets("Tracker")
Set ws2 = Sheets("Formulas")
'declare you worksheet, amend as required
LastRow = ws.Cells(ws.Rows.Count, "L").End(xlUp).Row
CompareVal = LastRow
'get the value to compare against, in this case from cell B1
Set Rng = ws2.Range("AF2:AF" & LastRow)
'set the range to compare against the value from B1
For Each c In Rng 'for each cell in the given range
If c.value < CompareVal Then c.ClearContents
'if value of cell is less than the value to compare against, clear the cell contents.
Next
End Sub
I saw no reaction. I know, that code refers to clear lower data than, but I don't know how to change it for my purpose.
In Excel: How to check if a cell is empty with VBA? I found the IsEmpty()
function. I changed
If c.value < CompareVal Then c.ClearContents
to
If IsEmpty(CompareVal.value) Then c.ClearContents
I get an error: Object required with debugger pointing on this line.
How can I autodelete values for the cell in another sheet located on the same row?