+ Reply to Thread
Results 1 to 7 of 7

VBA for data importing between workbooks.

  1. #1
    Registered User
    Join Date
    01-04-2020
    Location
    London
    MS-Off Ver
    2013
    Posts
    5

    VBA for data importing between workbooks.

    Hi,

    I have been tasked with creating a pallet tracking system for work, and i have encountered a problem which i'm unable to resolve with google.

    Each night at work we complete a Report which details pallet movements throughout the night; this sheet is attached and called "UK Print Sites Master (with After Cut-Offs) TEST FOR PALLETS)". In this workbook there is a tab called "Pallet Control" which collates the pallet movements from previous tabs into a simple table. These figures are represented by '0's in the table.

    During the day, a pallet tracking sheet is completed using the details from the report completed during the night; this sheet is attached and called "Pallet Tracking Sheet". The day staff normally print off the night report and manually enter the pallet movements, which i intend to streamline and create an data import function.

    So what i am having trouble with is the following:
    I would like to create an import function within the "Pallet Tracking Sheet" which will import the data from the "UK Print Sites Master". I would like the '0' figures from the "UK Print Sites Master" to be imported in the corresponding cells in the "Pallet Tracking Sheet".

    Other information you may require is that the name of the "UK Print Sites Master" file changes everyday. So i'm not sure whether it would be a .csv import of not.

    I am happy to answer any questions and thank you in advance for you help.

  2. #2
    Forum Contributor
    Join Date
    08-26-2014
    Location
    Finland
    MS-Off Ver
    365
    Posts
    199

    Re: VBA for data importing between workbooks.

    This will probably need a bit of refinement to fit your needs, but it is a start.
    This code will let the user select a workbook, and it will copy the whole sheet.
    Let me know if I was even close getting what you need :D

    Please Login or Register  to view this content.
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    01-04-2020
    Location
    London
    MS-Off Ver
    2013
    Posts
    5

    Re: VBA for data importing between workbooks.

    Hi banaanas,

    Thank you for your response.

    I have had a play with your code and the file selection works perfectly.

    I am now trying to copy specific cells from the sourceWs and paste them into the corresponding cells in the targetWs. I have tried the following code, however the .Copy function seems to bug and the .PasteSpecial function doesn't allow me to select values. This is this the code i have been trying:

    sourceWs Range("E16:F34").Copy
    targetWs Range("E16:F34").PasteSpecial

    This copy and paste function will need to be applied to different ranges also.

    Thank you so much for you assistance with this.

  4. #4
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,641

    Re: VBA for data importing between workbooks.

    Please use code tags when having code in your post.
    If the data goes to the same ranges:
    Please Login or Register  to view this content.
    If the data goes to different ranges (need to be the same size)
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    01-04-2020
    Location
    London
    MS-Off Ver
    2013
    Posts
    5

    Re: VBA for data importing between workbooks.

    Hi Jolivanes,

    I inserted the code you provided into the code supplied by banaanas and for some reason it's returning the following error message when i test it:
    "Compile error: Variable not defined"
    Is there something i'm missing?
    Please Login or Register  to view this content.

    Thanks again for your help.

  6. #6
    Forum Contributor
    Join Date
    08-26-2014
    Location
    Finland
    MS-Off Ver
    365
    Posts
    199

    Re: VBA for data importing between workbooks.

    Hi!
    Sorry for not replying, I was on vacation in Spain
    That error comes when you use the "Option Explicit" at the top of the code, and have a variable that is not declered.
    add this line below Dim dataRng

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    01-04-2020
    Location
    London
    MS-Off Ver
    2013
    Posts
    5

    Re: VBA for data importing between workbooks.

    Hi Banaanas,

    I have been asked to add another feature to the sheet you helped me with previously, and i was wondering if you are able to assist me again. The code is below:

    Please Login or Register  to view this content.
    I would like to adjust the code you produced for me to copy a range of cells from the last worksheet in a source workbook, and paste then into a specific range on a target workbook. I have tried to have a play about myself however i can't wrap my head around it.

    To help clarify, the source workbook will have worksheets named after dates of the month (ie; 1, 2, 3). I want to extract data from the last worksheet (range G16:G35) and past them into a target worksheet in cell range D16:D35.

    Furthermore, when i run the original code you produced for me, i receive the following message concerning the source sheet:

    Attachment 661120

    Is there a way to stop this from happening using VBA?

    Thank you in advance for you assistance.

+ 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. Importing and manipulating data between workbooks automatically
    By Richie_m21 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-18-2014, 04:23 PM
  2. [SOLVED] Importing and manipulating data between workbooks automatically
    By Richie_m21 in forum Excel General
    Replies: 3
    Last Post: 10-28-2014, 01:20 AM
  3. Importing data form other workbooks
    By Philsargent in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-19-2012, 07:33 AM
  4. Importing data from other workbooks
    By kurikinton in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-17-2012, 12:32 PM
  5. Importing Data from different workbooks
    By bs979 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-26-2008, 10:46 AM
  6. importing data from other offline workbooks
    By budman182 in forum Excel General
    Replies: 4
    Last Post: 07-19-2007, 10:39 PM
  7. Importing data from multiple closed workbooks
    By Judy in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-29-2005, 06:50 PM

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