Deleting cells in a loop
Andy,
No need to loop: this assumes that your header row is row 1, and the code will clear cells in
columns A-F, K-M, O-S
Sub Macro1()
Range("AR:AR").AutoFilter Field:=1, Criteria1:="TRUE"
Range("A2:F" & Rows.Count).SpecialCells(xlCellTypeVisible).Value = ""
Range("K2:M" & Rows.Count).SpecialCells(xlCellTypeVisible).Value = ""
Range("O2:S" & Rows.Count).SpecialCells(xlCellTypeVisible).Value = ""
Range("AR:AR").AutoFilter
End Sub
HTH,
Bernie
MS Excel MVP
"Andyjim" wrote in message
...
I am trying to use a loop to select a particular criteria (i.e. col AR = True
and then delete certain cells in that row. It was suggested I use
.clearcontents but I encountered an error something like "can't change merged
cell." I looked up a post that then suggested using .value = "" to handle
this error.
But the main reason for writing is that this loop isn't working. No cells
are being deleted. Any help would be greatly appreciated.
-Andy
With Sheets("Analysis")
Set TradesEntered = .Range("at17:at56")
End With
Dim clearrow
'Loop: Check for complete trades, delete
For X = 1 To TradesEntered.Count
Set ClosCheck = TradesEntered(X)
' For Each PastCheck In TradesEnteredPast
If ClosCheck.Value = "True" Then
With ClosCheck
'.Worksheet.Select
clearrow = ActiveCell.Row
Range("A" & clearrow & ":F" & clearrow).Value = ""
Range("K" & clearrow & ":M" & clearrow).Value = ""
Range("O" & clearrow & ":S" & clearrow).Value = ""
End With
End If
Next
|