SOLVED

Macro to clear cells adjacent to cells with text

Copper Contributor

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.

1 Reply
best response confirmed by LonnieCurrier (Copper Contributor)
Solution

@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 best response

Accepted Solutions
best response confirmed by LonnieCurrier (Copper Contributor)
Solution

@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

View solution in original post