Is my assumption correct that your error you refer to is that the line
containing See attached... is being deleted? If so, then following line
suggests there might be spaces in front of "See attached...." and you want to
trim them off so that you can compare See.
If Application.Trim(Left(.Cells(myrow, 1), 3)) _
= "See" Then myrow = myrow + 1
If so then you have an error or logic. The spaces must be trimmed first
before identifying the left three actual characters as follows otherwise the
Left function will return space and Se and when trimmed will be Se.
The following line trims spaces first and then gets the Left 3 characters.
If Left(Trim(.Cells(myrow, 1)), 3) _
= "See" Then myrow = myrow + 1
--
Regards,
OssieMac
"Yossy" wrote:
> Please I wouldn't know why this code is not working. I want to delete all
> contents below "Tile in month for the Period" in Column A across multiple
> sheets in my workbook. I get error. I want it to ignore "see attached file"
> i.e should not clear the content where it sees "see attached file".
>
> Sub Clearcontent()
> Dim targetcol As String
> Dim sh As Worksheet
> Dim myrow As Long
> Dim lastrowtodelete As Long
>
> targetcol = "A"
> For Each sh In ActiveWorkbook.Sheets
> 'If ActiveSheet.Name <> sh.Name Then
>
> With sh
> myrow = .Columns(targetcol).Find(What:="*Tile in month for the Period*", _
> after:=Cells(1, 1), LookIn:=xlValues, LookAt:=xlWhole, _
> SearchOrder:=xlByRows, SearchDirection:=xlNext).Row + 1
> If Application.Trim(Left(.Cells(myrow, 1), 3)) _
> = "See" Then myrow = myrow + 1
>
> lastrowtodelete = .Cells(myrow, targetcol).End(xlDown).Row
> .Range(.Cells(myrow, targetcol), .Cells(lastrowtodelete,
> targetcol)).ClearContents
> End With
>
> 'End If
> Next
> End Sub
>
> All help totally appreciated. Thanks a big bunch.
>
>
>
|