Object Required error on Weekly Summary sheet creation

  • Thread starter Thread starter davegb
  • Start date Start date
D

davegb

I'm removing dupes from a list. The following code gives an "object
required" error on the marked line. The variable is declared as a
range object, is set, and is recognized in the commands immediately
above. So why not in this line?
Sub WklySumWS()

Dim wbWkly As Workbook
Dim wsWklyLst As Worksheet
Dim wsWklySum As Worksheet
Dim sWklyShtName As String
Dim rStartCell As Range
Dim rTaskList As Range
Dim rTaskStart As Range
Dim rTask As Range
Dim rNextTask As Range
Dim sTask As String
Dim sNextTask As String
Dim lTask As Long
lTask = 1


Set wsWklyLst = ActiveSheet
Set rStartCell = wsWklyLst.Range("B1")


sWklyShtName = wsWklyLst.Name

'Create Weekly Summary Sheet
Sheets.Add.Activate
Set wsWklySum = ActiveSheet
Set rTaskStart = wsWklySum.Range("A1")


ActiveSheet.Name = sWklyShtName & " Summary"
wsWklySum.Move Before:=Sheets("Project Summary")
wsWklyLst.Range(rStartCell, rStartCell.End(xlDown)).Copy
wsWklySum.Range("A1").PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending


Set rTaskList = wsWklySum.Range(rTaskStart, rTaskStart.End(xlDown))

For Each rTask In rTaskList
sTask = rTask.Value
Set rNextTask = rTask.Offset(1, 0)
sNextTask = rNextTask
Do While sNextTask <> ""
Do While sTask = sNextTask
rNextTask.EntireRow.Delete <----OBJECT REQUIRED ERROR
Loop
Loop


Next rTask
End Sub

Thanks in advance.
 
It appears that you haven't declared your variables consistently. Put Option
Explicit before your sub and then compile the VBA project to figure out the
problems.
 
Oops, I think I goofed. :) What I'd recommend is defining a range to
delete while you go through your loop and once you are finished with the
whole range, delete the rows in question. Something like this

Set DeleteRange = Nothing

In the For next loop add ranges to delete

if DeleteRange is nothing then
Set DeleteRange = rNextTask
else
Set DeleteRange = union (DeleteRange,rNextTask)
end if

Once you are done with the For Next do this

DeleteRange.entirerow.delete
 
It appears that you haven't declared your variables consistently.  Put Option
Explicit before your sub and then compile the VBA project to figure out the
problems.
--
HTH,
Barb Reinhardt














- Show quoted text -

Thanks for the reply, but I've already done all that, as stated in my
original post.
 
Oops, I think I goofed.  :)   What I'd recommend is defining a range to
delete while you go through your loop and once you are finished with the
whole range, delete the rows in question.   Something like this

Set DeleteRange = Nothing

In the For next loop add ranges to delete

if DeleteRange is nothing then
    Set DeleteRange = rNextTask
else
    Set DeleteRange = union (DeleteRange,rNextTask)
end if

Once you are done with the For Next do this

DeleteRange.entirerow.delete
--
HTH,
Barb Reinhardt














- Show quoted text -

Thanks for the suggestions. I'm still trying to figure out why that
original code fails, so I can learn from my mistakes. Any ideas?
 
Back
Top