• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

clear the contents of a few sheets in a certain range if...

Marco1975

New Member
Hi all,

I can't run this macro.

Code:
Sub cancel()
Dim WS_Count As Integer
Dim i As Integer
Dim rng As Range
Dim cell As Variant
WS_Count = ActiveWorkbook.Worksheets.Count

Set rng = Sheets(i).Range("j16:j215")
For i = 7 To WS_Count

For Each cell In rng
If cell.Value <> "X" Then
cell.ClearContents
End If
Next
Next i
End Sub

I should clear the contents of a few sheets in the range ( J16 : J215 ) if the cell doesn't contain the character "X" .
sheets control start from number 7 .
Who can help me?
Thanks.
 
Try this Code.

Code:
Sub cancel()
Dim WS_Count As Integer
Dim i As Integer
Dim rng As Range
Dim cell As Variant
WS_Count = ActiveWorkbook.Worksheets.Count


For i = 7 To WS_Count
Set rng = Sheets(i).Range("j16:j215")
For Each cell In rng
If cell.Value <> "X" Then
cell.ClearContents
End If
Next
Next i
End Sub


For more clarification, Can you upload the relative Excel file with you query
 
Back
Top