Object Required error on Weekly Summary sheet creation

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.
 
B

Barb Reinhardt

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.
 
B

Barb Reinhardt

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
 
D

davegb

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.
 
D

davegb

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Variable not defined? 5
Error 424 Object required 2
Looping within a loop 1
Object Required error 1
PasteSpecial failed 2
Error 424, Object required 2
Can't paste today 6
Trying to "clean up" some code... 1

Top