Help with an if...then error message


Posted by John on December 14, 2000 6:57 AM

I am a newbie to programming and have run into a problem with this procedure:


' Clean up unnecessary data
For counter = 1 To 1000
Set curcell = Worksheets("Sheet1").Cells(counter, 3)
If curcell.Value = ("*" Or "***") Then Next counter

Set curcell = Range(Cells(counter, 1), Cells(counter + 1000, 20))

curcell.ClearContents

Whenever I try and run these lines, I always receive a compile error of "block if without end if"

The intent here is to move down a column in a sorted list until one finds a cell not containing "*" or "***" and then to clear all the remaining data below lines containing the matching cells.


Any help is appreciated!

thx

Posted by Celia on December 14, 2000 3:39 PM

curcell.ClearContents


Sub Search_and_Destroy()
Dim searchRange As Range, cell As Range, c As Integer
'Set the column to be searched
c = 3
'Set the range to search
Set searchRange = Range(Cells(1, c), Cells(65536, c).End(xlUp))
'Step through each cell in theRange
For Each cell In searchRange
'Conditional check re the cell's value
If cell.Value = "*" Or cell.Value = "***" Then
'If condition met, clear contents below and exit the loop
Range(cell.Offset(1, 0), Cells(65536, c)).EntireRow.ClearContents
Exit For
'Exit the conditional check
End If
'Loop to the next cell
Next
End Sub



Posted by maz on December 15, 2000 2:30 AM

curcell.ClearContents

This is a fundamental error. For every 'if' you must type an 'End if'.e.g.
For counter = 1 To 1000 curcell.ClearContents

End If
This may not be the only error in this macro, but it is certainly the immediate problem