PC Review


Reply
Thread Tools Rate Thread

Copy to current workbook loop

 
 
=?Utf-8?B?anVzdG1l?=
Guest
Posts: n/a
 
      11th Dec 2006
HI,

I have put a macro together from browsing the posts.

I have a template that has 3 sheets. The information on sheet2 ("INTL")
actually comes from one sheet each in 6 other workbooks that are regularly
updated on our server, from which I am copying and pasting into my new
template, one below the other in the same columns.
I am trying to create a new macro to automate that process

So, I'd like my routine when I receive a new batch of files to be that I:

1) open a new blank workbook from the template "Blend"
2) I will save the blank workbook to a name like 061210_input
3) Then I will run my macro from the new workbook.

The macro will:
1) Prompt me to open a file to get the data from
2) copy All data in columns A through J on sheet 2 of that file, no matter
what the sheet is named (there may be intermittent blank rows, but I need
all data in those columns. Column data may have blanks. Column I is most
dependable to have data)
3) paste it into columns A through J of the newly saved "blend" workbook
sheet2 (named "INTL")
4) Leave both workbooks open without saving
5) Set the destination file as the active workbook again
6) Prompt me for the next file to copy from
5) Copy columns A through J on sheet 2 of that file
8) find the first blank row on sheet "INTL" after last data and paste
directly below it into columns A-J.
9) prompt me for the next file name and so on until all the files, at which
time I'll cancel the open dialog.


I have been hacking at this macro for awhile I just found this code on
another post from Mike, but not I'm kinda clueless.
Please help!


Sub consolidate()
Dim origin As String
Dim orgn As Workbook, dest As Workbook
Dim Blended as Workbook
Dim WSI as Worksheet
Set blended = ActiveSheet
Set wsI = Blended.Sheets("INTL")
Do
Application.ScreenUpdating = False
origin = Application.GetOpenFilename("Microsoft Office Excel Files
(*.xl*;*.xls;*.xla;*.xlm;*.xlc;*.xlw),*.xl*;*.xls;*.xla;*.xlm;*.xlc;*.xlw")
If origin = "False" Then Exit Sub
Workbooks.Open origin, 0, True
Set orgn = ActiveWorkbook
If ThisWorkbook.ReadOnly Then
MsgBox ("The destination file has been opened as a Read-Only file and
cannot be written to...Cancelling")
End If

Dim LastRow As Long
orgn.Activate
With orgn.sheets(2)
LastRow = orgn.sheets(2).Cells(Rows.Count, "I").End(xlUp).Row
Set MyRange = wsI.Cells(LastRow, "I").Offset(1, -8)
..Range("A1", .Cells.SpecialCells(xlCellTypeLastCell)).Copy _
Destination:=MyRange.PasteSpecial(xlPasteValues)
End With
wsI.Activate


Loop
End Sub

Thanx!!!!!!
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy worksheet into current workbook Gerard Microsoft Excel Misc 0 19th Feb 2010 03:31 PM
loop through a column on a workbook copying data on each row to another workbook, then copy data back to the original workbook burl_rfc Microsoft Excel Programming 1 1st Apr 2006 08:48 PM
copy,paste and loop through workbook =?Utf-8?B?VFVOR0FOQSBLVVJNQSBSQUpV?= Microsoft Excel Misc 0 6th Dec 2005 12:31 PM
Copy a range of cells in an unopened workbook and paste it to the current workbook topstar Microsoft Excel Programming 3 24th Jun 2004 12:50 PM
VBA loop will not copy new workbook after about 100 times. igrep4fun Microsoft Excel Programming 3 20th Mar 2004 04:10 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:03 AM.