LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 175
Default For-each to copy rows to another workbook

I received help on this from Tom Ogilvy (which I appreciate, of
course), but I need additional help. I thought I would try to lay out
what I needed differently, as I tend to be too wordy...

This macro should go down a list, and copy rows based on 2 criteria.
1) to determine what the next workday is, like Monday, Tues, etc (a
formula is in place to do this)
2) based on the next workday, it should read a certain table that
contains the warehouse row numbers to look for in the source workbook.

If tomorrow is a Tuesday, then it should look at a table with a range
name of CycleCount_Tuesday, and during the For-each section, copy all
rows from the source list that contain these warehouse row numbers,
and paste them to the target workbook.

Please look at the coding so far. Currently there are no errors given
when I run this. The cursor ends up at the bottom of the source list
like it should, but nothing at all is copied.
My guess is that the assignment is not made during the If-Then-Else
section, so it finds nothing that matches the criteria.
Thanks to all for your help.
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
Worksheets("Cycle Count").Activate

'DayOfWeek is the numeric value of the next weekday based on a
formula.
'CycleCount_Monday (Tues, Wed, etc) are ranges containing the
warehouse rows.
'*****I think this is where the problem is. Assignment value does not
seem
' to be given to RowsToCount.*****
If Range("DayOfWeek") = 2 Then
Set RowsToCount = CycleCount_Monday
ElseIf Range("DayOfWeek") = 3 Then
Set RowsToCount = CycleCount_Tuesday
ElseIf Range("DayOfWeek") = 4 Then
Set RowsToCount = CycleCount_Wednesday
ElseIf Range("DayOfWeek") = 5 Then
Set RowsToCount = CycleCount_Thursday
ElseIf Range("DayOfWeek") = 6 Then
Set RowsToCount = CycleCount_Friday

End If

'This sets the range name TempColumnName to the column on the source
list
'to be read by the macro.
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"

'Makes sure cursor starts at the top of the source list.
Range("FirstRowOfficialList").Select
ActiveCell.Offset(1, 0).Select

'Looks at each row for matching criteria based on above IF-Then-Else.
For Each cell In Range("TempColumnName")
If Not RowsToCount Is Nothing Then
If cell.Value = RowsToCount Then
CopyRows 'sub below that will 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

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

End Sub

Sub CopyRows()
'Copies rows to target workbook.

Rows(ActiveCell.Row).Select
Selection.Copy

Windows("Inventory Wk of BLANK.xls").Activate
Sheets("Data Dump").Select

Range("B65536").End(xlUp).Offset(1, -1).Select

ActiveSheet.Paste
ThisWorkbook.Activate

End Sub

 
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
Copy Autofiltered rows to another workbook using macro ashish128 Excel Discussion (Misc queries) 2 July 27th 07 01:25 PM
copy rows and paste in another workbook steven Excel Programming 0 February 15th 07 03:56 PM
Copy Range with Additional Rows to New Workbook Kim[_16_] Excel Programming 13 March 28th 06 05:27 AM
copy rows to another workbook sortilege Excel Discussion (Misc queries) 1 December 16th 05 03:41 PM
how to copy succeeding rows from source workbook to destination w. chris Excel Programming 0 March 8th 05 01:51 PM


All times are GMT +1. The time now is 10:42 AM.

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"