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.
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
1 Reply
- Riny_van_EekelenPlatinum 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