+ Reply to Thread
Results 1 to 9 of 9

Opening file, copy and paste range

Hybrid View

  1. #1
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,310

    Re: Opening file, copy and paste range

    Didn't see a problem with your code except the pastespecial statement, so I modified it a bit. See if it works...
    Sub cy_pst()
        Dim wbTarget As Workbook, wbSource As Workbook
        Dim strFileToOpen As String, vData As Variant
        
        Set wbTarget = ThisWorkbook
        strFileToOpen = Application.GetOpenFilename("Excel Files *.xls* (*.xls*),", , "Please choose the clockwise data file")
        If strFileToOpen = "False" Then
            MsgBox "No file selected.", vbExclamation, "Sorry!"
            Exit Sub
        Else
            Set wbSource = Workbooks.Open(strFileToOpen, , 1)
        End If
        
        vData = wbSource.Sheets("H28_F116 Data").Range("A10:BG5233")
        wbTarget.Sheets("H28_F116 CW Data").Range("A10:BG5233") = vData
        wbSource.Close
        
        strFileToOpen = Application.GetOpenFilename("Excel Files *.xls* (*.xls*),", , "Please choose the counterclockwise data file")
        If strFileToOpen = "False" Then
            MsgBox "No file selected.", vbExclamation, "Sorry!"
            Exit Sub
        Else
            Set wbSource = Workbooks.Open(strFileToOpen, , 1)
        End If
        
        vData = wbSource.Sheets("H28_F116 Data").Range("A10:BG5233")
        wbTarget.Sheets("H28_F116 CCW Data").Range("A10:BG5233") = vData
        wbSource.Close
        
        wbTarget.Save
        MsgBox "Data Transferred"
    End Sub
    Last edited by dangelor; 06-03-2019 at 01:47 PM.

+ 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 and paste in a new excel file.
    By Vagelisr in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-11-2018, 07:31 AM
  2. Copy Visible Range in Excel and Paste into Text File
    By jpv5 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-14-2016, 09:15 AM
  3. [SOLVED] Copy same range in many excel files and paste into a main file
    By dualaudio454252 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-15-2014, 05:25 PM
  4. macro to copy used range and paste in the body tag of a html file/text file
    By amethystfeb in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-24-2014, 08:34 PM
  5. Macro required for copy a range, create a new txt file and paste it
    By gm2612 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-28-2013, 07:25 AM
  6. Code to copy range from 200 + workbooks and paste into one csv import file
    By CharlieMappley in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-14-2013, 10:41 AM
  7. Copy and paste without opening excel file
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-20-2010, 10:14 AM

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