Forum Discussion
LonnieCurrier
May 16, 2020Copper Contributor
Macro to clear cells adjacent to cells with text
For each row, I need to clear the cell in column B if column A contains any text. The number of rows may vary. The attached example has Before and After sheets.
- May 16, 2020
LonnieCurrier Try this very small macro.
Sub ClearIfText() Dim DataRange As Object Dim i As Integer Set DataRange = Range("A1").CurrentRegion For i = 1 To DataRange.Rows.Count If DataRange.Cells(i, 1) <> "" Then DataRange.Cells(i, 2).ClearContents End If Next End Sub
Riny_van_Eekelen
May 16, 2020Platinum Contributor
LonnieCurrier Try this very small macro.
Sub ClearIfText()
Dim DataRange As Object
Dim i As Integer
Set DataRange = Range("A1").CurrentRegion
For i = 1 To DataRange.Rows.Count
If DataRange.Cells(i, 1) <> "" Then
DataRange.Cells(i, 2).ClearContents
End If
Next
End Sub