View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Yossy Yossy is offline
external usenet poster
 
Posts: 127
Default Delete rows of data in multiple sheets

I still get the same error -" Object Variable not set with block variable"

Please help...........I want to delete rows of data below "Title of Month"
in multiple sheets. Thus where there is "Title of Month in all sheets in my
workbook, the code should look below the title and delete the data only in
the row beneath the title until the last data. In this case my data are in
Column A.

Thanks

"Don Guillett" wrote:

You end if is in the wrong place. However, you may like this NON selection
better. Notice the DOTS. I also delete all rows from the bottom up myrow+1.
If you don't want that change to. However, blanks could be a problem.
LastRowToDelete = .Cells(myrow, TargetCol).End(xldown).Row

Also, best to fully describe your find.

Sub DeleteData_Don()
TargetCol = "A"
For Each sh In ThisWorkbook.Sheets
If ActiveSheet.Name < sh.Name Then
With sh
myrow = .Columns(TargetCol).Find(What:="Title for Month", _
After:=Cells(1, 1), LookIn:=xlValues, LookAt:=xlWhole, _
SearchOrder:=xlByRows, SearchDirection:=xlNext).Row

LastRowToDelete = .Cells(Rows.Count, TargetCol).End(xlUp).Row
.Range(.Rows(myrow + 1), .Rows(LastRowToDelete)).Delete
End With
'MsgBox myrow
'MsgBox LastRowToDelete
End If
Next
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Yossy" wrote in message
...
Anyone know why I am getting this error - "Object Variable or with block
variable not set" Please help... I want to delete rows of data below
"Title
of Month" in multiple sheets. Thus where there is "Title of Month in all
sheets, the code should look below the title and delete the data only in
the
row beneath the title until the last data. In this case my data are in
Column
A.

Sub DeleteData()
TargetCol = "A"
For Each sh In ThisWorkbook.Sheets
If ActiveSheet.Name < sh.Name Then
Sheets(sh.Name).Select
End If
Set f = Columns(TargetCol).Find(What:="Title for Month")
fRow = f.Row
LastRowToDelete = Cells(fRow, TargetCol).End(xlDown).Row
Range(Rows(fRow + 1), Rows(LastRowToDelete)).Delete
Next
End Sub


Thanks a big bunch