Rowland Hamilton
Active Member
- Joined
- Nov 13, 2009
- Messages
- 250
Folks:
I can't seem to get this code to work. I received an 1004 error eventually, indicating it does not like my method of selecting the the worksheets in the source workbook.
I want to cycle through the worksheets in the workbook ("United States (de linked).xlsm") and
select only the ws with tab names that include "*-Line item*" (which is preceded by a cc # and sometimes followed by an s as in "5049-Line Items")
Then copy a contiguous, but varing range of data from each sheet and
paste it to a master worksheet in the workbook named "Line items-Combined.xlsm" which contains the macro.
Here is the code
Thank you
Rowland
I can't seem to get this code to work. I received an 1004 error eventually, indicating it does not like my method of selecting the the worksheets in the source workbook.
I want to cycle through the worksheets in the workbook ("United States (de linked).xlsm") and
select only the ws with tab names that include "*-Line item*" (which is preceded by a cc # and sometimes followed by an s as in "5049-Line Items")
Then copy a contiguous, but varing range of data from each sheet and
paste it to a master worksheet in the workbook named "Line items-Combined.xlsm" which contains the macro.
Here is the code
Sub Populate_line_item_workbooka()
Dim MasterWB As Workbook
Dim SourceWB As Workbook
Dim ws As Worksheet
Set MasterWB = Workbooks("Line items-Combined.xlsm")
Set SourceWB = Workbooks("United States (de linked).xlsm")
For Each ws In SourceWB.Worksheets
If ws.Name Like "*-Line item" Then
ws.Select
Range("A3").Select
Call Copy_move_line_items
Exit For
End If
Next ws
End Sub
Sub Copy_move_line_items()
'copy
Range("A3").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
'paste
Windows("Line items-Combined.xlsm").Activate
Sheets("Master-Incoming").Activate
Range("A65000").Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub
Thank you
Rowland