View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
excelnut1954 excelnut1954 is offline
external usenet poster
 
Posts: 175
Default For-each to copy rows to another workbook

I've tried different things to eliminate the error I get. It's a 424
Object required error shown below. See the ****************** marker.
Since my VBA projects are a secondary part of my job, I'm able to
dive into it only occasionally. So, since Tom last responded, I've
spent some time trying to learn about what might be causing this
error. I'm stuck. I've tried adding different Dim statements, Set
statements. I don't know what Object the error is referring to. Do I
need to declare the individual sheets as objects? Each workbook?
Any suggestions would be appreciated.
Thanks,
J.O.

Sub CycleCount()

Dim RowsToCount As Range
Dim CycleCount_Monday As Object
Dim CycleCount_Tuesday As Object
Dim CycleCount_Wednesday As Object
Dim CycleCount_Thursday As Object
Dim CycleCount_Friday As Object
Dim DayOfWeek As Integer

'Opens up the Blank inventory workbook (target)
ChDir "S:\Furniture Staging List\Staging List Inventories"
Workbooks.Open Filename:= _
"S:\Furniture Staging List\Staging List Inventories\Inventory
Wk of BLANK.xls"

'Switch back to original (source) file
ThisWorkbook.Activate

'DayOfWeek is the numeric value of the next weekday based on a
formula.
'CycleCount_Monday, Tues, etc are ranges containing the warehouse row
'numbers to look for on the list.

With Sheets("Cycle Count")

If Range("DayOfWeek") = 2 Then
Set RowsToCount = Range("CycleCount_Monday")
ElseIf Range("DayOfWeek") = 3 Then
Set RowsToCount = Range("CycleCount_Tuesday")
ElseIf Range("DayOfWeek") = 4 Then
Set RowsToCount = Range("CycleCount_Wednesday")
ElseIf Range("DayOfWeek") = 5 Then
Set RowsToCount = Range("CycleCount_Thursday")
ElseIf Range("DayOfWeek") = 6 Then
Set RowsToCount = Range("CycleCount_Friday")

End If
End With

Worksheets("Official List").Activate
Application.Goto Reference:="FirstRowOfficialList"
ActiveCell.Offset(1, 0).Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Names.Add Name:="TempColumnName", RefersToR1C1:= _
"='Official List'!R6C3:R416C3"

Range("FirstRowOfficialList").Select
ActiveCell.Offset(1, 0).Select

'Looks at each row for matching criteria based on above IF-Then-Else.
With Sheets("Official List")
For Each cell In Range("TempColumnName")
If Not RowsToCount Is Nothing Then

'********this is where I get "Runtime error 424 Object
Required" error ***********
If Not IsError(applicaton.Match(cell.Value, RowsToCount, 0))
Then

CopyRows 'sub to perform copy routine
Else
MsgBox "Nothing copied because " & vbNewLine & _
"Value of Range DayofWeek is " & Range("DayofWeek").Value
End If
End If

ActiveCell.Offset(1, 0).Select
Next cell
End With

ThisWorkbook.Activate
ActiveWorkbook.Names("TempColumnName").Delete

End Sub