+ Reply to Thread
Results 1 to 2 of 2

Copy Cells from one workbook to another

Hybrid View

  1. #1
    Registered User
    Join Date
    08-12-2013
    Location
    Denton, Texas
    MS-Off Ver
    Excel 2010
    Posts
    89

    Copy Cells from one workbook to another

    Hello,

    I recorded a macro to copy and paste values from several different ranges in one workbook, then open a destination workbook and paste them there. For the most part it just goes back and forth till it's done. It works just fine but I was wondering if there was a more efficient way of doing this? Maybe with the use of an Aeeay Thank you in advance for looking at my code.


    Worksheets("ECN_Form").Activate
        Worksheets("ECN_Form").Range("AA1").Select
        Selection.Copy
        ChDir "\\psf\Home\Desktop\TestEnviroment\"
        Workbooks.Open Filename:="\\psf\Home\Desktop\TestEnviroment\LogTest.xlsm"
        Range("A:A").End(xlDown).Offset(1, 0).Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Windows("ECN New Layout 5 CntrAcrss.xlsm").Activate
            
        Worksheets("ECN_Form").Range("R5").Select
        Selection.Copy
        Windows("LogTest.xlsm").Activate
        Range("B2").End(xlDown).Offset(1, 0).Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Windows("ECN New Layout 5 CntrAcrss.xlsm").Activate
        
        Worksheets("ECN_Form").Range("F5").Select
        Selection.Copy
        Windows("LogTest.xlsm").Activate
        Range("C2").End(xlDown).Offset(1, 0).Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Windows("ECN New Layout 5 CntrAcrss.xlsm").Activate
        
        With myClipbd
            .SetText Me.Controls.Item("TxtFromToSum").Text
            .PutInClipboard
        End With
        Windows("LogTest.xlsm").Activate
        Range("D2").End(xlDown).Offset(1, 0).Select
        ActiveSheet.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon:= _
            False
        Windows("ECN New Layout 5 CntrAcrss.xlsm").Activate
        
        Worksheets("ECN_Form").Range("A10").Select
        Selection.Copy
        Windows("LogTest.xlsm").Activate
        Range("E2").End(xlDown).Offset(1, 0).Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Windows("ECN New Layout 5 CntrAcrss.xlsm").Activate
        
        Worksheets("ECN_Form").Range("K11").Select
        Selection.Copy
        Windows("LogTest.xlsm").Activate
        Range("F2").End(xlDown).Offset(1, 0).Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Windows("ECN New Layout 5 CntrAcrss.xlsm").Activate
        
        Worksheets("ECN_Form").Range("F3").Select
        Selection.Copy
        Windows("LogTest.xlsm").Activate
        Range("G2").End(xlDown).Offset(1, 0).Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Windows("ECN New Layout 5 CntrAcrss.xlsm").Activate
        
        Worksheets("ECN_Form").Range("S36").Select
        Selection.Copy
        Windows("LogTest.xlsm").Activate
        Range("I2").End(xlDown).Offset(1, 0).Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Windows("ECN New Layout 5 CntrAcrss.xlsm").Activate
        
        Worksheets("ECN_Form").Range("R3").Select
        Selection.Copy
        Windows("LogTest.xlsm").Activate
        Range("J2").End(xlDown).Offset(1, 0).Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        
        Range("H2").End(xlDown).Offset(1, 0).Value = "PENDING"
        
        Range("A1").Select
        Application.CutCopyMode = False
        ActiveWorkbook.Save
        ActiveWindow.Close
            
        Worksheets("ECN_Form").Visible = False
        
        'Open_F = Application.GetOpenFilename()
    
        Application.ScreenUpdating = True
        UserForm1.Hide
        Application.Visible = True
        Application.DisplayAlerts = False
        ThisWorkbook.Close

  2. #2
    Valued Forum Contributor
    Join Date
    11-02-2012
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    564

    Re: Copy Cells from one workbook to another

    Sub Test()
    Dim MyArr As Variant
    Dim z As Long
    Windows("ECN New Layout 5 CntrAcrss.xlsm").Activate
    Worksheets("ECN_Form").Activate
    MyArr = Array(Range("AA1").Value, Range("r5").Value, Range("F5").Value, "Something", Range("A10").Value, Range("K11").Value, Range("F3").Value, "PENDING", Range("S36").Value, Range("R3").Value)
    
    ChDir "\\psf\Home\Desktop\TestEnviroment\"
    Workbooks.Open Filename:="\\psf\Home\Desktop\TestEnviroment\LogTest.xlsm"
    
    For z = 0 To UBound(MyArr)
    ActiveWorkbook.ActiveSheet.Range("A2").Activate
        ActiveCell.Offset(0, z).End(xlDown).Offset(1, 0).Value = MyArr(z)
    Next z
    End Sub
    ________________________________________________________
    If your problem is solved, update the thread as SOLVED: Go to the top of the first post-Select Thread Tools-Select Mark thread as Solved OR - Go to the first post - Click edit- Click Advance- Just below the word "Title:" you will see a dropdown with the word No prefix.- Change to Solve- Click Save.

    Show your gratitude to the person who helped you solving your problem by clicking on star button at the bottom of such post.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Copy range to new workbook w/some cells as values & some cells as formulas in new workbook
    By happydayze in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-14-2013, 12:42 PM
  2. [SOLVED] Copy Specific Cells Across all worksheets in a Workbook and Paste Into single New Workbook
    By thunt13 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-14-2013, 10:43 AM
  3. Copy two cells in on workbook to another workbook based on two criteria, but more
    By oldboots in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-16-2013, 06:17 AM
  4. Copy two cells in on workbook to another workbook based on two criteria, but more
    By oldboots in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-16-2013, 05:44 AM
  5. Workbook to workbook copy by avoiding blank cells
    By sivdin in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-17-2011, 05:38 AM

Tags for this Thread

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