fhzhkunming
New Member
- Joined
- Mar 4, 2021
- Messages
- 30
- Office Version
- 365
- Platform
- Windows
Hi Members,
I would like to clear content of a dynamic range based on a condition, i,e., I want to clear content in range "D:I" if value in cells of column "I" is 0. In current situation, I wanted to clear "D14:I17". But I got an error message "Run-time error '1004': Application-defined or object-defined error. Here is my code:
Please help me out. Thanks in advance.
Frank
I would like to clear content of a dynamic range based on a condition, i,e., I want to clear content in range "D:I" if value in cells of column "I" is 0. In current situation, I wanted to clear "D14:I17". But I got an error message "Run-time error '1004': Application-defined or object-defined error. Here is my code:
VBA Code:
Dim rowNum As Integer
Dim Lrow As Long
With ActiveSheet
Lrow = Cells(Rows.Count, "I").End(xlUp).Row
For rowNum = Lrow To 2 Step -1
If Range("I" & rowNum).Value = 0 Then
.Range("D:I" & Lrow).ClearContents
End If
Next rowNum
End With
End Sub
Please help me out. Thanks in advance.
Frank