LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 167
Default Copying Data Between Two Spreadsheets

Bob,

The following code can be run from any worksheet except the file you are
reading from and the file you will write to. The originating file will
ALWAYS be opened in read-only, and the destination file cannot be open by
another user. If it is an error message will display and the copy with
cancel.

Sub consolidate()
Dim origin As String, destin As String
Dim orgn As Workbook, dest As Workbook
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
destin = Application.GetOpenFilename("Microsoft Office Excel Files
(*.xl*;*.xls;*.xla;*.xlm;*.xlc;*.xlw),*.xl*;*.xls; *.xla;*.xlm;*.xlc;*.xlw")
If destin = "False" Then Exit Sub
Workbooks.Open origin, 0, True
Set orgn = ActiveWorkbook
Workbooks.Open destin, 0, False
Set dest = ActiveWorkbook
If dest.ReadOnly Then
MsgBox ("The destination file is in use and cannot be written
to...Cancelling")
GoTo inuse
End If
orgn.Sheets("Detail Data").Range("H6:H990").Copy _
Destination:=dest.Sheets("Consolidated Data").Range("A2")
dest.Save
inuse:
orgn.Close
dest.Close
Application.ScreenUpdating = True
End Sub

Good luck! Let me know if there's anything more I can help with.

Mike


"Bob" wrote:

I need to copy data from spreadsheet €œABC€ (not its real name) thats located
on a shared drive, to spreadsheet €œXYZ€ (also not its real name) located on
my local hard drive. The range of cells to be copied from ABC will always be
€˜Detail Data!H6:H990. The destination starting cell will always be
€˜Consolidated Data!A2.

The macro would need to prompt the user for both the originating and
destination locations (using Windows standard File | Open dialog box).
Since ABC is located on a shared drive, there may be times when ABC is in use
by another user and therefore locked, except for read-only capabilities.
Consequently, the macro would also need to check for that condition, and if
it exists, automatically select the read-only option.

Being new to VBA, I would greatly appreciate any help in writing the
aforementioned macro, especially since two spreadsheets are involved.

Thanks.

 
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
Copying Web Tables To Spreadsheets jaygreg New Users to Excel 3 December 29th 08 02:26 AM
How can I automate copying data from one into several spreadsheets AndyL82 Excel Discussion (Misc queries) 2 January 21st 07 01:45 PM
copying excel spreadsheets Lisa Excel Discussion (Misc queries) 2 December 31st 06 01:56 AM
Copying Data from various spreadsheets STEVEB Excel Programming 0 January 6th 06 04:51 PM
Copying spreadsheets-did not work tazsdad Excel Discussion (Misc queries) 1 December 5th 05 11:48 PM


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

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

About Us

"It's about Microsoft Excel"