Results 1 to 3 of 3

Thread: Transfer data between workbooks VBA

  1. #1
    Neophyte iain88's Avatar
    Join Date
    Apr 2019
    Posts
    4
    Articles
    0
    Excel Version
    office 365

    Transfer data between workbooks VBA



    Register for a FREE account, and/
    or Log in to avoid these ads!

    Hi

    i get an error on my macro below on the top line and cant work out why? wanting to transfer data from one workbook to another, with the data getting added to the bottom of the new list.
    work books attached.

    ------------------------------
    Code:
    Sub MyAmazingMacro()
    
    
    Dim Name As String, Device As String, staffdate As String
    Worksheets("form").Select
    Name = Range("B2")
    Device = Range("C2")
    StartToday = Range("D2")
    Worksheets("asset").Select
    Worksheets("asset").Range ("A1")vba test 1.xlsmvba test 2.xlsx
    If Worksheets("asset").Range("A1").Offset(1, 0) <> "" Then
    Worksheets("asset").Range("A1").End(x1down).Select
    End If
    ActiveCell.Offset(1, 0).Select
    ActiveCell.Value = Name
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = Device
    ActiveCell.Offset(0, 2).Select
    ActiveCell.Value = staffdate
    
    
    End Sub
    Last edited by Pecoflyer; 2019-04-26 at 08:27 AM.

  2. #2
    Conjurer Logit's Avatar
    Join Date
    Nov 2016
    Posts
    225
    Articles
    0
    Excel Version
    2007
    .
    The following macro presumes both workbook are located on your desktop :

    Code:
    
    Sub Update()
    
    
        Dim wbk As Workbook
        Dim folderPath As String
        Dim Filename As String
        Dim wb As Workbook
        folderPath = Environ("USERPROFILE") & "\Desktop\" 'contains folder path
        If Right(folderPath, 1) <> "\" Then folderPath = folderPath + "\"
        Filename = Dir(folderPath & "VBA Test 2.xlsx")   '
        Do While Filename <> ""
            Application.DisplayAlerts = False
            Application.ScreenUpdating = False
            Set wb = Workbooks.Open(folderPath & Filename)
            Sheets("Asset").Range("A1:D50" & Range("A" & Rows.Count).End(xlUp).Row).Copy    'change range to copy here
            ThisWorkbook.Worksheets("form").Range("a" & Rows.Count).End(xlUp)(2).PasteSpecial
            ThisWorkbook.Worksheets("form").Activate
            ThisWorkbook.Worksheets("form").Range("A1").Select
            Workbooks(Filename).Close True
            Filename = Dir
        Loop
        
        Application.ScreenUpdating = True
        Application.DisplayAlerts = True
    
    
    End Sub

  3. #3
    Administrator Pecoflyer's Avatar
    Join Date
    Oct 2011
    Location
    Brussels Belgium
    Posts
    1,675
    Articles
    0
    Excel Version
    2010 on Xubuntu
    @iain
    In the future please wrap code with code tags ( click Go advanced - select code click the #button)
    I did it for you this time
    Thank you Ken for this secure forum.

Posting Permissions

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