I have a formula in Col C on sheet "Import Templates last updated" that returns a blank if the cell in the same row in Col A is blank
I have tried to write code to clear the formula in Col C that returns a blank where Col B in the same row is blank, but the code is not clearing these formulas
For e.g. if C21:C500 returns a blank then these formula are to be cleared where Col B in the same row is blank i.e empty
It would be appreciated if someone could amend my code
Code:
=IF(A21="","",LEFT(A21,SEARCH("run",A21)-2))
I have tried to write code to clear the formula in Col C that returns a blank where Col B in the same row is blank, but the code is not clearing these formulas
For e.g. if C21:C500 returns a blank then these formula are to be cleared where Col B in the same row is blank i.e empty
Code:
Sub ClearDataInColC()
Dim ws As Worksheet
Dim lastRow As Long
Dim i As Long
' Set the worksheet you want to work with
Set ws = ThisWorkbook.Sheets("Import Templates last updated")
' Find the last used row in Column B
lastRow = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row
' Loop through each row in Column B
For i = 2 To lastRow ' Assuming row 1 has headers
If IsEmpty(ws.Cells(i, "B").Value) And ws.Cells(i, "C").Formula = "" Then
ws.Cells(i, "C").ClearContents
End If
Next i
End Sub
It would be appreciated if someone could amend my code