+ Reply to Thread
Results 1 to 3 of 3

import sheet

  1. #1
    Registered User
    Join Date
    08-09-2013
    Location
    Milan
    MS-Off Ver
    Excel 2010
    Posts
    9

    import sheet

    Hi to everybody,
    I am new user in this forum and also I am new with excel macro , I need your help

    I am creating a dashboard in excel composed by 1 sheet (called DB) with the data and other sheets with graphs and so on…
    I would like to create a macro to import and update automatically the sheet DB with the data of another file.
    The sheet DB in the dashboard is exactly the same of the sheet of the file that I need to import.

    The script has to:
    1) ask to the user where is the file to update
    2) the user has to select the file
    3) automatically it has to copy the values of a specific sheet in this file in the DB sheet in the dashboard

    I found this script on line but I need help to adapt for what I need…

    Sub Example5()
    Dim basebook As Workbook
    Dim mybook As Workbook
    Dim sourceRange As Range
    Dim destrange As Range
    Dim SourceRcount As Long
    Dim N As Long
    Dim rnum As Long
    Dim MyPath As String
    Dim SaveDriveDir As String
    Dim FName As Variant

    SaveDriveDir = CurDir
    MyPath = "C:\Data"
    ChDrive MyPath
    ChDir MyPath

    FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls), *.xls", _
    MultiSelect:=True)
    If IsArray(FName) Then
    Application.ScreenUpdating = False
    Set basebook = ThisWorkbook

    For N = LBound(FName) To UBound(FName)
    Set mybook = Workbooks.Open(FName(N))

    rnum = LastRow(basebook.Worksheets(1)) + 1

    Set sourceRange = mybook.Worksheets(1).Range("A1:Z35000")
    SourceRcount = sourceRange.Rows.Count
    Set destrange = basebook.Worksheets(1).Cells(rnum, "A")

    basebook.Worksheets(1).Cells(rnum, "D").Value = mybook.Name
    ' This will add the workbook name in column D if you want

    With sourceRange
    Set destrange = basebook.Worksheets(1).Cells(rnum, "A"). _
    Resize(.Rows.Count, .Columns.Count)
    End With
    destrange.Value = sourceRange.Value

    mybook.Close False

    Next
    End If
    ChDrive SaveDriveDir
    ChDir SaveDriveDir
    Application.ScreenUpdating = True
    End Sub


    Thanks in advance!!!

    Luca

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: import sheet

    need sample files, source and target
    If solved remember to mark Thread as solved

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: import sheet

    Hi, Luca,

    please add code-tags to the procedure as requested in Forum Rule #3 - thank you.

    Code is untested, and iou haven´t pointed out whether to append or replace the contents on sheet DB.

    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

+ 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] Bulk import. (Copy Data from one sheet to a main sheet with conditions)
    By DanzaNZ in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-18-2013, 12:24 AM
  2. How do I import every 5th line from sheet 1 to sheet 2
    By MSMOMMALW6 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-16-2013, 06:04 PM
  3. Import data from specfic column in Sheet Sheet to List Box userform
    By z-eighty2 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-18-2013, 05:54 PM
  4. File import - select file and import sheet(1) from closed workbook
    By Armitage2k in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-22-2011, 03:15 AM
  5. Replies: 3
    Last Post: 07-17-2007, 09:52 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