+ Reply to Thread
Results 1 to 18 of 18

Import specific cells from a user chosen spreadsheet

  1. #1
    Forum Contributor
    Join Date
    02-16-2008
    Location
    Mansfield, TX
    Posts
    324

    Import specific cells from a user chosen spreadsheet

    Hi, I need some help. I need to import some spreadsheets that are sent to me into a master database spreadsheet. I have attached both below. The complaintstest.xls is the master database and the other is the sheet that will be imported. What I would like to happen is when the macro is run, the user will be able to select the sheet they would like to import through a dialog box. After the sheet is selected the macro will import the cells from the selected sheet into the master database in a particular order. In the master database example on row 2 I have listed the columns from the sheet to be imported in the corresponding column on the database sheet. This will macro will be run a couple of times a week so the macro will have to find the next empty row to start the import on. If you have any questions, please let me know!

    Thanks!
    Attached Files Attached Files
    Last edited by dcgrove; 11-30-2009 at 02:07 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Need help with a macro to import specific cells from a user chosen spreadsheet

    Hello dcgrove,

    Can you post a copy of the ComplaintsTest workbook in 2003 format?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor
    Join Date
    02-16-2008
    Location
    Mansfield, TX
    Posts
    324

    Re: Need help with a macro to import specific cells from a user chosen spreadsheet

    Leith, I switched them. Thanks for looking at it.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Need help with a macro to import specific cells from a user chosen spreadsheet

    Hello dcgrove,

    I found the Invoice number on the ComplaintsTest worksheet 2009, but no Credit Invoice Number. Did you miss adding a column for this entry?

  5. #5
    Forum Contributor
    Join Date
    02-16-2008
    Location
    Mansfield, TX
    Posts
    324

    Re: Need help with a macro to import specific cells from a user chosen spreadsheet

    Leith, I have uploaded a new complaints test.xls that have the correct corresponding columns in row 2. I must have saved the wrong copy of the file previously.


    Thanks!

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Need help with a macro to import specific cells from a user chosen spreadsheet

    Hello dcgrove,

    Thanks for the update. Is the PFG Credit number the same as the Credit Invoice number?

  7. #7
    Forum Contributor
    Join Date
    02-16-2008
    Location
    Mansfield, TX
    Posts
    324

    Re: Need help with a macro to import specific cells from a user chosen spreadsheet

    Leith, it is.

    Thanks!

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Need help with a macro to import specific cells from a user chosen spreadsheet

    Hello dcgrove,

    The macro will display the Open File Dialog to let them choose the file to open. A UserForm is displayed to inform the user to select the opened workbook and activate the sheet to import. Once that is done, go back to the master workbook and click continue. The macro will then import the data to the next available row in the master workbook. The selected workbook is then closed after the data is imported. Here is the macro which has been added to the attached workbook.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    02-16-2008
    Location
    Mansfield, TX
    Posts
    324

    Re: Import specific cells from a user chosen spreadsheet

    Hi Leith, everything is working except for one issue. Instead of finding the next empty row to import the data on, it is importing it on row three and overwriting anything that is there. This macro is way above my skill level so I was unable to figure out why it happens.

    Thanks for your help!

    Clayton

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Import specific cells from a user chosen spreadsheet

    Hello Clayton,

    I downloaded the file and ran it. It starts with row 3 and adds to the next available row. Even with data in row 3 at the start, it started copying the data at line 4. No data was overwritten. I ran this on Excel 2003. Which version of Excel are you using?

  11. #11
    Forum Contributor
    Join Date
    02-16-2008
    Location
    Mansfield, TX
    Posts
    324

    Re: Import specific cells from a user chosen spreadsheet

    Leith, I am on excel 2007. Everytime I run the macro it starts importing at row 3. I also noticed that the columns appear to be off.

    The file below is what happened after I imported the data. I have also added a file with some more rows of data.

    Thanks for your help!
    Clayton
    Attached Files Attached Files

  12. #12
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Import specific cells from a user chosen spreadsheet

    Hello Clayton,

    The columns were offset because you now have 11 columns in Credits requested instead of 10. That has been fixed. Do you not want the copied data to start at row 3? I used row 3 because the master file has auto-filters in row 2. I will change the starting line to whatever you want. Here is the updated macro. Changes are in blue font.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  13. #13
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Import specific cells from a user chosen spreadsheet

    Hello Clayton,

    I found the problem with the starting row. Use this version and not the previous one I posted. Here is the macro code. Change is blue font.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  14. #14
    Forum Contributor
    Join Date
    02-16-2008
    Location
    Mansfield, TX
    Posts
    324

    Re: Import specific cells from a user chosen spreadsheet

    Leith, thanks for everything! The macro works great. For my own understanding, can you explain what this section of the code does? I would like to know how I can rearrange the location of the destination range should the destination sheet change. Thanks!

    Please Login or Register  to view this content.

  15. #15
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Import specific cells from a user chosen spreadsheet

    Hello Clayton,

    The array called Data holds the column letter for the destination cell. This array makes it easier to map the destination cells to the source cells. There are currently eleven columns used. The array is zero based. The first element is 0, the second element is 1, etc. The statement below copies the contents of the source cell "A1" to the column "G" of next available row, N, on the destination sheet. For this example, N will be 3.
    Please Login or Register  to view this content.
    The column argument of the Cells property will accept either a number or letter(s). Numbers are faster in a loop, but letters are more easily understood by people.
    Last edited by Leith Ross; 11-30-2009 at 12:52 PM.

  16. #16
    Forum Contributor
    Join Date
    02-16-2008
    Location
    Mansfield, TX
    Posts
    324

    Re: Import specific cells from a user chosen spreadsheet

    Thanks for the explanation Leith! I tried to add a column of data to import but it is not being copied over. Here is the code I have that is not working. I added a column in the data array (there are now 12 columns of data to import) and added a corresponding "DSTRNG.Cells" line below it. Can you tell me what I did wrong?

    Please Login or Register  to view this content.

  17. #17
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Import specific cells from a user chosen spreadsheet

    Hello Clayton,

    The destination is fine. You forgot to extend your source range...
    Please Login or Register  to view this content.

  18. #18
    Forum Contributor
    Join Date
    02-16-2008
    Location
    Mansfield, TX
    Posts
    324

    Re: Import specific cells from a user chosen spreadsheet

    Leith, you are the man... Thank you for all of your help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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