Results 1 to 3 of 3

Copying Data Via A Macro

Threaded View

  1. #1
    Registered User
    Join Date
    09-29-2008
    Location
    USA
    Posts
    16

    Copying Data Via A Macro

    I have the following macro which copies data from one spreadsheet to another spreadsheet. The 2 files are specifically named in the database so they must have those specific file names in order for the macro to work.

    Is there a way to set up this macro so that it automatically copies the data in the file that is active at the time (File1 in the attached code) to File2? File2 will always be the same file name, so that part of the macro is fine as it is. The active spreadsheet will always be the same format (so the Source Cells will work) but it may have a different file name each time.

    Sub DatabaseCopy()
    '
    ' DatabaseCopy Macro
    ' Macro recorded 11/12/2008 by JLZ
    '
    ' Keyboard Shortcut: Ctrl+d
    '
        Range("B6:E9").Select
        Selection.Copy
        Range("B6").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        
        Dim wks1 As Worksheet
        Dim wks2 As Worksheet
        
        Set wks1 = Workbooks("File1.xls").Worksheets("Sheet1")
        Set wks2 = Workbooks("File2.xls").Worksheets("Sheet1")
    ' syntax is [destination].Value = [source].Value
    
        wks2.Range("A3").Value = wks1.Range("C9").Value
        wks2.Range("B3").Value = wks1.Range("E2").Value
        wks2.Range("C3").Value = wks1.Range("E3").Value
        wks2.Range("D3").Value = wks1.Range("E4").Value
        wks2.Range("E3").Value = wks1.Range("C6").Value
    Last edited by lj123; 11-21-2008 at 07:23 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1