Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default Error 424, Object required

On line 70 (as noted below), it's telling me I need an object. Can you tell
me how to give it one?


Sub PrepareReport()

Dim wksLoc As Worksheet
Dim wksTemp As Worksheet
Dim wksNew As Worksheet
Dim deptCell As Range
Dim deptLoop As Range
Dim strCell As Range
Dim strLoop As Range

Set wksLoc = Sheets("Locations")
Set wksTemp = Sheets("Template")


'Select the list of depts
With wksLoc
Set deptLoop = .Range("c1", .Range("c1").End(xlDown))
End With

'Select the list of stores
With wksLoc
Set strLoop = .Range("a2", .Range("a2").End(xlDown))
End With

'Loop through each dept and str
For Each deptCell In deptLoop
With wksTemp
.Range("a8").Value = deptCell
dept = .Range("a8").Value
End With
For Each strCell In strLoop
With wksTemp
.Range("a5").Value = strCell
.Calculate
End With

'Create a new sheet for each dept
wksTemp.Copy Befo=wksTemp
Set wksNew = ActiveSheet

With wksNew
.Name = Trim(dept)
'Replace formulas with values
.Cells.Copy
.Cells.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
End With

'Paste the next store
CopyNext wksTemp

Next strCell
Next deptCell

End Sub


Sub CopyNext(wks As Worksheet)

Dim rngfill As Range


With wksTemp
'.Outline.ShowLevels RowLevels:=2, ColumnLevels:=2
wks.Rows("8:20").Copy
End With
With wksNew
Set rngfill = Nothing
Set rngfill = .Range("b" & .Rows.Count).End(xlUp) 'IT'S ASKING ME FOR
AN OBJECT HERE.
Set rngfill = rngfill.Offset(2, -1)
rngfill.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks:=False, Transpose:=False
rngfill.PasteSpecial Paste:=xlFormats, Operation:=xlNone,
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
End With
End Sub
--
Thanks,
PTweety
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Error 424, Object required

wksNew is not referenced in Sub CopyNext(wks As Worksheet)

Either you need to declare wksNew as a global variable or modify Sub
CopyNext to take wKsNew.....

CopyNext wksTemp, wksNew

Sub CopyNext(wks As Worksheet,wksNew as WorkSheet)
''your code
End Sub



--
If this post helps click Yes
---------------
Jacob Skaria


"pickytweety" wrote:

On line 70 (as noted below), it's telling me I need an object. Can you tell
me how to give it one?


Sub PrepareReport()

Dim wksLoc As Worksheet
Dim wksTemp As Worksheet
Dim wksNew As Worksheet
Dim deptCell As Range
Dim deptLoop As Range
Dim strCell As Range
Dim strLoop As Range

Set wksLoc = Sheets("Locations")
Set wksTemp = Sheets("Template")


'Select the list of depts
With wksLoc
Set deptLoop = .Range("c1", .Range("c1").End(xlDown))
End With

'Select the list of stores
With wksLoc
Set strLoop = .Range("a2", .Range("a2").End(xlDown))
End With

'Loop through each dept and str
For Each deptCell In deptLoop
With wksTemp
.Range("a8").Value = deptCell
dept = .Range("a8").Value
End With
For Each strCell In strLoop
With wksTemp
.Range("a5").Value = strCell
.Calculate
End With

'Create a new sheet for each dept
wksTemp.Copy Befo=wksTemp
Set wksNew = ActiveSheet

With wksNew
.Name = Trim(dept)
'Replace formulas with values
.Cells.Copy
.Cells.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
End With

'Paste the next store
CopyNext wksTemp

Next strCell
Next deptCell

End Sub


Sub CopyNext(wks As Worksheet)

Dim rngfill As Range


With wksTemp
'.Outline.ShowLevels RowLevels:=2, ColumnLevels:=2
wks.Rows("8:20").Copy
End With
With wksNew
Set rngfill = Nothing
Set rngfill = .Range("b" & .Rows.Count).End(xlUp) 'IT'S ASKING ME FOR
AN OBJECT HERE.
Set rngfill = rngfill.Offset(2, -1)
rngfill.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks:=False, Transpose:=False
rngfill.PasteSpecial Paste:=xlFormats, Operation:=xlNone,
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
End With
End Sub
--
Thanks,
PTweety

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Error 424, Object required

You do not define wksNew in your current procedure. wks is passed in but
wksNew does not exist. It is defined in the previous procedure but that ends
when the sub ends. Additionlly you should be using option explicit to stop
vba from creating vairables on the fly...

Sub CopyNext(wks As Worksheet)
Dim rngfill As Range

With wksTemp
'.Outline.ShowLevels RowLevels:=2, ColumnLevels:=2
wks.Rows("8:20").Copy
End With
With wksNew 'Where is wksNew coming from???

--
HTH...

Jim Thomlinson


"pickytweety" wrote:

On line 70 (as noted below), it's telling me I need an object. Can you tell
me how to give it one?


Sub PrepareReport()

Dim wksLoc As Worksheet
Dim wksTemp As Worksheet
Dim wksNew As Worksheet
Dim deptCell As Range
Dim deptLoop As Range
Dim strCell As Range
Dim strLoop As Range

Set wksLoc = Sheets("Locations")
Set wksTemp = Sheets("Template")


'Select the list of depts
With wksLoc
Set deptLoop = .Range("c1", .Range("c1").End(xlDown))
End With

'Select the list of stores
With wksLoc
Set strLoop = .Range("a2", .Range("a2").End(xlDown))
End With

'Loop through each dept and str
For Each deptCell In deptLoop
With wksTemp
.Range("a8").Value = deptCell
dept = .Range("a8").Value
End With
For Each strCell In strLoop
With wksTemp
.Range("a5").Value = strCell
.Calculate
End With

'Create a new sheet for each dept
wksTemp.Copy Befo=wksTemp
Set wksNew = ActiveSheet

With wksNew
.Name = Trim(dept)
'Replace formulas with values
.Cells.Copy
.Cells.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
End With

'Paste the next store
CopyNext wksTemp

Next strCell
Next deptCell

End Sub


Sub CopyNext(wks As Worksheet)

Dim rngfill As Range


With wksTemp
'.Outline.ShowLevels RowLevels:=2, ColumnLevels:=2
wks.Rows("8:20").Copy
End With
With wksNew
Set rngfill = Nothing
Set rngfill = .Range("b" & .Rows.Count).End(xlUp) 'IT'S ASKING ME FOR
AN OBJECT HERE.
Set rngfill = rngfill.Offset(2, -1)
rngfill.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks:=False, Transpose:=False
rngfill.PasteSpecial Paste:=xlFormats, Operation:=xlNone,
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
End With
End Sub
--
Thanks,
PTweety

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Object Required Error Minitman Excel Programming 7 July 1st 08 01:11 AM
Object Required Error Minitman Excel Programming 2 May 7th 08 08:04 AM
Object required error 424 why getting? Chet Excel Programming 2 April 6th 07 07:26 PM
Error 424 - Object Required [email protected] Excel Programming 2 December 30th 04 03:38 PM
Syntax Error Runtime Error '424' Object Required sjenks183 Excel Programming 1 January 23rd 04 09:25 AM


All times are GMT +1. The time now is 02:42 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"