+ Reply to Thread
Results 1 to 51 of 51

Import content from separate Excel files to a single spreadsheet?

  1. #1
    Registered User
    Join Date
    12-01-2006
    Posts
    55

    Import content from separate Excel files to a single spreadsheet?

    Hi everyone,

    I've got several Excel files that need to be edited separately.
    Once they have been edited, I need to paste the content of each file in a single separate Excel file.

    Is there a way to retrieve the content from all the files in a folder, and merge it in a single file?

    For example:
    3 separate files > File1, File2, File3

    Merged file, sheet1
    File1
    File2
    File3

    I'd really appreciate any help.
    Last edited by paokun; 02-06-2010 at 11:52 AM.

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: How to import content from separate Excel files to a single spreadsheet?

    Hi paokun
    A good place to start is with workbook by ravishankar
    http://www.excelforum.com/attachment...eet-nimrod.xls
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    Registered User
    Join Date
    12-01-2006
    Posts
    55

    Re: How to import content from separate Excel files to a single spreadsheet?

    Hi pike,

    Wow, this is a great macro!
    Thanks, it does the job pretty neatly.

    Now, starting from this sheet, how can I import only the visible cells?

    If that's not possible, being able to import only specific columns would already help.
    Last edited by paokun; 02-03-2010 at 07:36 PM.

  4. #4
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: How to import content from separate Excel files to a single spreadsheet?

    hey paokun
    try something like this as its easier to follow and change

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    12-01-2006
    Posts
    55

    Re: How to import content from separate Excel files to a single spreadsheet?

    Hi pike,

    Thanks for your new reply and sorry for my old one.
    Where should I put that code?
    Could you please attach a spreadsheet containing it?

    Thanks :-)

  6. #6
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: How to import content from separate Excel files to a single spreadsheet?

    Hi paokun

    have a look at the code in this one
    Attached Files Attached Files

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: How to import content from separate Excel files to a single spreadsheet?

    Pike, Paokun,

    This variation on Pike's macro allows you to expand/contract the # of files in question by only editing one line of code...marked in red. Just add more filenames.
    Please Login or Register  to view this content.

    How/Where to install the macro:

    1. Open up your workbook
    2. Get into VB Editor (Press Alt+F11)
    3. Insert a new module (Insert > Module)
    4. Copy and Paste in your code (given above)
    5. Get out of VBA (Press Alt+Q)
    6. Save your sheet

    The macro is installed and ready to use. Press Alt-F8 and select it from the macro list.
    Last edited by JBeaucaire; 02-04-2010 at 07:06 PM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  8. #8
    Registered User
    Join Date
    12-01-2006
    Posts
    55

    Re: How to import content from separate Excel files to a single spreadsheet?

    Hi pike,

    Thanks, getting closer. Actually this extracts the first horizontal line of a spreadsheet, but how can I make it extract a vertical column (or a range of cells?).
    I have the advantage that the text is in the same column in all files.

    Actually I'm dealing with hundreds of files so it would be also better to make it extract the content of all files in a folder, rather than having to specify each file name. Also, the files get open when running the macro, isn't there a way to keep them close?

    And one more thing, is there a way to extract only the visible cells? In this case, rather than selecting a column or a range of cells, extracting only the visible cells in each file would be perfect.

    This is pure science to me, so I have no clue of how you came up with this code.

  9. #9
    Registered User
    Join Date
    12-01-2006
    Posts
    55

    Re: How to import content from separate Excel files to a single spreadsheet?

    Hi JBeaucaire,

    Thanks for your post!
    This is an improvement because now the files get closed when the macro stops running.
    Also, I had to remove & "]" from the line below as it couldn't find the files.

    Workbooks.Open (ThisWorkbook.Path & "]" & MyFiles(i))

    So now I get the row 1 of each file imported, but as I wrote above, is there a way to import a range of cells? Or only the visible cells?

  10. #10
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: How to import content from separate Excel files to a single spreadsheet?

    Sorry, that was supposed to be an "/" not a "]".

    If you want to:

    1) Open all the files in a single folder and import them into a single sheet, data stacked
    2) Close the imported files

    I have a standard macro for that, you won't have to list the files, just set the correct path.

    What's the range of data or column(s) you want to import?
    What's the path to the folder?
    Are all the files named similarly? Or should we just import everything in that folder regardless of name?

  11. #11
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: How to import content from separate Excel files to a single spreadsheet?

    Here's the standard macro. I've highlighted the sections you would need to edit to suit your needs.

    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 02-10-2010 at 09:48 PM.

  12. #12
    Registered User
    Join Date
    12-01-2006
    Posts
    55

    Re: How to import content from separate Excel files to a single spreadsheet?

    Hi, thanks for the quick reply.

    1) Open all the files in a single folder and import them into a single sheet, data stacked
    Yes, basically I just put the macro file in the folder and would like to import all the files in this folder. If the macro file needs to be put in a separate folder, then I'd like to import the files that are in: C:\Project1\

    2) Close the imported files
    Yes, that would be better.

    3) I'd like to import columns F M N O and exclude the header line 2 in each file.

    4) I'd like to have the filename and worksheet appear in the export file so that I know where the text comes from.

    The four columns above are the only visible columns, all the rest is hidden. Still, probably it's more complicated to have the macro import only the visible text, is that why you asked for the range of cells?

    Thanks again for your help, I really appreciate it.

  13. #13
    Registered User
    Join Date
    12-01-2006
    Posts
    55

    Re: How to import content from separate Excel files to a single spreadsheet?

    Ops sorry I was replying to your message then I saw the macro.
    Can you edit the macro based on the info I wrote above?

  14. #14
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: How to import content from separate Excel files to a single spreadsheet?

    Quote Originally Posted by paokun View Post
    Ops sorry I was replying to your message then I saw the macro.
    Can you edit the macro based on the info I wrote above?
    Why don't you take a whack at that, it will help you understand the code if you give it a shot.

  15. #15
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: How to import content from separate Excel files to a single spreadsheet?

    Hmm, just read your answers, always more features needed than originally thought...

    Quote Originally Posted by paokun View Post
    1) Open all the files in a single folder and import them into a single sheet, data stacked
    Yes, basically I just put the macro file in the folder and would like to import all the files in this folder. If the macro file needs to be put in a separate folder, then I'd like to import the files that are in: C:\Project1\
    You can edit that import path, yes?
    I would put the macro file in a separate folder...

    2) Close the imported files
    Yes, that would be better.
    Already does that...

    3) I'd like to import columns F M N O and exclude the header line 2 in each file.
    Um...FMNO should land in columns ABCD?
    Rows3---> bottom of the data? That part is already highlighted, you can edit that...

    4) I'd like to have the filename and worksheet appear in the export file so that I know where the text comes from.
    Listed where? Think of everything I might as next in regard to this item and include a complete explanation of the output requirements. (nudge)

    The four columns above are the only visible columns, all the rest is hidden. Still, probably it's more complicated to have the macro import only the visible text, is that why you asked for the range of cells?
    Nah, it's equally cumbersome or equally simple...depends on your comfort level.

    Copying all the visible data only, that could be helpful, yes indeed.
    Last edited by JBeaucaire; 02-04-2010 at 07:51 PM.

  16. #16
    Registered User
    Join Date
    12-01-2006
    Posts
    55

    Re: Import content from separate Excel files to a single spreadsheet?

    Hi JBeaucaire,

    Sorry and thanks for the reply!
    Using the last code that you pasted, I'm having some problems in defining the range, so I can still import only the first row.
    Range("A1:A" & LR).EntireRow.Copy

    How shall I write that I need rows FMNO?

    As for the filename, currently it only shows ABC_OUTPUT, and I can't see the correct filename in the green cell. Also, some worksheets have Japanese names and won't be displayed.

    And regarding the visible text.. if it's not too cumbersome, can you add that feature?

    I know I'm really asking too much, thanks for your patience!

  17. #17
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Import content from separate Excel files to a single spreadsheet?

    Quote Originally Posted by paokun View Post
    Using the last code that you pasted, I'm having some problems in defining the range, so I can still import only the first row.
    Range("A1:A" & LR).EntireRow.Copy

    How shall I write that I need rows FMNO?
    Um...are you saying you ONLY want row1? Or that you want all the visible rows? I'm getting confused here.

    Row1 only:
    Please Login or Register  to view this content.
    All rows of visible data:
    Please Login or Register  to view this content.
    As for the filename, currently it only shows ABC_OUTPUT, and I can't see the correct filename in the green cell. Also, some worksheets have Japanese names and won't be displayed.
    Huh? You know I'm not sitting in the room with you, so I can't see things like "green cells" and Japanese anything.

  18. #18
    Registered User
    Join Date
    12-01-2006
    Posts
    55

    Re: Import content from separate Excel files to a single spreadsheet?

    I wish you were sitting here! ;-)

    I've created a draft that looks like the files I have.
    File1.xls has two worksheets, one with Japanese characters.
    If you unhide the columns and rows, you'll see all the unneeded cells.

    In the Result file you see how I'd like File1.xls to be exported.

    Hopefully now it'll make more sense!
    Attached Files Attached Files

  19. #19
    Registered User
    Join Date
    12-01-2006
    Posts
    55

    Re: Import content from separate Excel files to a single spreadsheet?

    Sorry man, almost 3 AM here and 5 hours to sleep, I'll check it later from the office. Sorry to have dragged you on this, but seeing how far you've gone, I'm positive in a good outcome ;-)

    Thanks again for all the help!

  20. #20
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Import content from separate Excel files to a single spreadsheet?

    Here you go...and you should know, uploading the sample file and sample results doc made this simple SIMPLE to understand. A picture is worth a 1000 words!

    Please Login or Register  to view this content.

    Put this macro into your RESULTS workbook. Don't save that workbook in the same folder as your Project1 files. Also, make sure there is a folder called IMPORTED inside the Project1 folder, the macro will try to move the imported files into there as it goes.
    Last edited by JBeaucaire; 02-10-2010 at 09:51 PM.

  21. #21
    Registered User
    Join Date
    12-01-2006
    Posts
    55

    Re: Import content from separate Excel files to a single spreadsheet?

    Hi JBeaucaire,

    Thanks a lot for the new code, I'm pretty sure I'm following your instructions as I don't get any 'debug' warning, however when I click on the macro, I get the two questions but then nothing gets imported.

    Also, the files are not moved in the 'imported' folder.

    Hmm do you know what the possible problem could be?

  22. #22
    Registered User
    Join Date
    02-04-2010
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: Import content from separate Excel files to a single spreadsheet?

    what would be the best way to create a quoting system with a master excel spreadsheet that has about 20,000 rows. I need to able to quickly type in multiple item numbers and generate a sheet with all the selected items and their additional information in numerous columns including a column of pictures.

    And to top it off once they are pulled from the master sheet they are automatically in order in terms of a specific aspect.

    Any help or suggestions to different software would be great

  23. #23
    Registered User
    Join Date
    12-01-2006
    Posts
    55

    Re: Import content from separate Excel files to a single spreadsheet?

    Hi plateman,

    I'd need something like that too, but to avoid tricking other users and myself too, can you open a different topic with your question?
    This topic is to import many files into one rather than the opposite, so it would be best to keep it only related to it.

    Thanks! :-)

  24. #24
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Import content from separate Excel files to a single spreadsheet?

    1) The macro goes in a regular module (module1, module2, etc)
    2) What is the fPath folder name? Did you edit it? Check the spelling...it must be exactly right and end with \.
    3) Did you create the Imported folder inside that fPath folder?

    Try going into the VBeditor and using F8 on the macro to step through it one line at a time....keep pressing F8. When you pass the fName = Dir line of code, put your mouse over the fName variable...what value pops up? File1.xls?

  25. #25
    Registered User
    Join Date
    12-01-2006
    Posts
    55

    Re: Import content from separate Excel files to a single spreadsheet?

    Hi and good morning!
    Thanks for getting back to me on this.

    1) The macro is in module1
    2) The folder path is C:\Documents and Settings\ABC\Desktop\Exporttrial\Original\
    3) The import folder path is C:\Documents and Settings\ABC\Desktop\Exporttrial\Original\Imported\

    Then I click the button, small flickering, but no result imported.

  26. #26
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Import content from separate Excel files to a single spreadsheet?

    Did you do this?

    Quote Originally Posted by JBeaucaire View Post
    Try going into the VBeditor and using F8 on the macro to step through it one line at a time....keep pressing F8. When you pass the fName = Dir line of code, put your mouse over the fName variable...what value pops up? File1.xls?

  27. #27
    Registered User
    Join Date
    12-01-2006
    Posts
    55

    Re: Import content from separate Excel files to a single spreadsheet?

    Hi,
    I've tried, but no value comes out, only fName=""
    Above it I have fName = Dir("*.XLS") and the XLS files are in the right folder.

  28. #28
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Import content from separate Excel files to a single spreadsheet?

    It appears there is an error in the location of the files and the path, and perhaps the filenames. I just ran the macro again on my own desktop folder and it pulled in all the files in there...

    I know it probably doesn't matter, but make the XLS into lowercase xls as shown in the original macro.

    Just for chuckles, you could change it *.* instead of *.xls just to see if the macro can see anything.
    Last edited by JBeaucaire; 02-11-2010 at 08:57 PM.

  29. #29
    Registered User
    Join Date
    12-01-2006
    Posts
    55

    Re: Import content from separate Excel files to a single spreadsheet?

    Hi, thanks for the new reply.
    I've tried changing the filename and putting *.* but no luck.
    It may depend on the fact that I have the language settings set to Japanese, but I've got that at home as well and yesterday I could extract some text.

    I'll try again with my home pc and let you know. In the meantime, if you can upload the ZIP together with your folder structure, I could try with it.

    Do you think it may depend on the fact I'm using Office 2003 in the office?
    At home I'm using the 2010 beta and yesterday it was running smoothly.

    Thanks again and sorry to be a pain.

  30. #30
    Registered User
    Join Date
    12-01-2006
    Posts
    55

    Re: Import content from separate Excel files to a single spreadsheet?

    Hi JBeaucaire,

    I've tried at home and this time it works, but I still only get displayed the first line (which is the header line that I don't need).
    Filename and worksheet work great with Japanese characters too, this is great!

  31. #31
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Import content from separate Excel files to a single spreadsheet?

    There's no reason at all you should be getting the first row from the source files.
    Please Login or Register  to view this content.
    ...we don't even include row1 in the copy command.

    The only difference in the macro I tested on my system and the one I uploaded is the path to my files was "C:\Test1\"... everything else is identical.

    I put 3 different copies of your File1 in there with different names. Works great. I can't fathom your different results. I would be spending time running the code with F8 (one line of code at a time) so I could switch back and forth between the editor and the workbook, try to see what's failing at the copy part.

  32. #32
    Registered User
    Join Date
    12-01-2006
    Posts
    55

    Re: Import content from separate Excel files to a single spreadsheet?

    Hmm I've been trying with F8 and when it calculates the latest row including text, the result is = 2

    LR = ws.Range("A" & Rows.Count).End(xlUp).Row 'Find last row and copy data edit range to suit

    I don't know if that depends on the fact that some hidden rows have no text at all?

    Can you send me a ZIP file of the working result?

  33. #33
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Import content from separate Excel files to a single spreadsheet?

    I suppose you could change this, though I didn't need to:
    Please Login or Register  to view this content.

  34. #34
    Registered User
    Join Date
    12-01-2006
    Posts
    55

    Re: Import content from separate Excel files to a single spreadsheet?

    It WORKED!!!

    This is wonderful programming, you're a genius!

    Now, the only problem left is that if a file has several worksheets, it cannot import them correctly.
    Basically it separates them well, but it always only import the text of the active visible worksheet (basically the one shown when you open the file).

    Do you know how to copy the text contained in each single worksheet inside a file?
    Last edited by paokun; 02-06-2010 at 09:47 AM.

  35. #35
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Import content from separate Excel files to a single spreadsheet?

    Quote Originally Posted by paokun View Post
    Now, the only problem left is that if a file has several worksheets, it cannot import them correctly.
    Oops. Well, that's what happens when you oversimplify the sample data, every sample sheet had the same fake data, so I didn't spot the programming error sooner. Sorry about that.

    One tiny change:
    Please Login or Register  to view this content.

    Also, change this...
    Please Login or Register  to view this content.

  36. #36
    Registered User
    Join Date
    12-01-2006
    Posts
    55

    Re: Import content from separate Excel files to a single spreadsheet?

    Perfect. That fixed the issue, now I've got everything in one single file!
    This is great, I had to import over 1,000 files and the job was done really quickly.

    Thanks again very much for your HUGE help, I really appreciate it!!!

  37. #37
    Registered User
    Join Date
    12-01-2006
    Posts
    55

    Re: Import content from separate Excel files to a single spreadsheet?

    Hi JBeaucaire,

    Back to the forum.
    I've spent a few days working with the script you created, and I have a few tweaks to ask you:

    1. If, among the visible cells, there's a full row without text, the script would stop importing there, even if below it there's some cell with text. Is it possible to import all un-hidden cells (or a range of rows), even if there are empty rows in between?

    2. Rather than having the filename and worksheet in one single row, would it be possible to have the filename on Column A, worksheet name on Column B, and the imported text starting from Column C?
    For example:

    Filename1 - Sheet1 - Imported text
    Filename1 - Sheet1 - Imported text
    Filename1 - Sheet2 - Imported text
    Filename2 - Sheet1 - Imported text

    This way it would be possible to filter the imported cells via filename and worksheet, and I wouldn't need any green line separating them.

    I don't know if you can still check these two issues, but that would be really appreciated.
    Please let me know if you have any question, and thanks again for your help.
    Last edited by paokun; 02-10-2010 at 11:04 AM.

  38. #38
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Import content from separate Excel files to a single spreadsheet?

    Quote Originally Posted by paokun View Post
    1. If, among the visible cells, there's a full row without text, the script would stop importing there, even if below it there's some cell with text. Is it possible to import all un-hidden cells (or a range of rows), even if there are empty rows in between?
    That's not correct. The code isn't importing like that. It's spotting the
    Please Login or Register  to view this content.
    These lines of code read:
    Find the last row of data by looking UP from the bottom of column F. Blanks within the data do not effect this spotting process.
    Then copy all visible rows of data from row2 down thru the spotted bottom row.


    The only way data would be missed is if we've chosen the wrong column to look up in.

    Recheck that, F8 your way through the macro and when it gets to that part of the code, see what value is going into LR and then see if that doesn't cover the range.

  39. #39
    Registered User
    Join Date
    12-01-2006
    Posts
    55

    Re: Import content from separate Excel files to a single spreadsheet?

    HI JBeaucaire,

    Thanks for the quick reply.
    Yep, the line LR = ws.Range("F" & Rows.Count) imports everything in column F even if there are empty cells in between.

    However, if the last cell with text in column F is F30, and I have some text in M35, M35 won't be imported, it will only go as far as M30.

    It would be best if it could check a range of cells and not only F, but I've tried using LR = ws.Range("F:O" & Rows.Count) but I get an error.

  40. #40
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Import content from separate Excel files to a single spreadsheet?

    Quote Originally Posted by paokun View Post
    Yep, the line LR = ws.Range("F" & Rows.Count) imports everything in column F even if there are empty cells in between.
    Nope...I realize you're having an issue and we'll work through it, but we need to clarify what each line of code does. The line of code you cited above doesn't import anything. It serves only to find the bottom row of data.
    Please Login or Register  to view this content.
    The second line of code does the actual copy job and it only copies visible data. So nothing hidden should be seen. The sample files you gave earlier this code worked fine on, so if there is some significant difference, perhaps we should look at the new files you're trying.

    However, if the last cell with text in column F is F30, and I have some text in M35, M35 won't be imported, it will only go as far as M30.
    Ah, is this the real issue? Spotting the bottom row properly is a pain sometimes. Most of my sheets, the first column (column A) always has something in it for every row of data, you don't have a key column like that on your worksheet? Also, having stuff hidden makes that a little trickier if the key column is hidden too.

    Try this, your mileage may be better:

    Please Login or Register  to view this content.

  41. #41
    Registered User
    Join Date
    12-01-2006
    Posts
    55

    Re: Import content from separate Excel files to a single spreadsheet?

    Hi,

    Actually in my current project it's not an issue, all rows in column A have text.
    However, this is a great macro, so I wanted to have something that imports all the visible cells regardless of where the text is.

    The last code that you pasted works, but there's one more little thing that should be changed.
    Now all columns are imported even if A has some blank cells, but the filename and worksheet name still show up after the last cell with text in A.

    If I change:
    NR = .Range("A" & .Rows.Count).End(xlUp).Row + 1 'Next row

    into
    NR = .Range("A" & .Rows.Count).SpecialCells(xlCellTypeLastCell).Row

    works, but then I have some empty lines after the last cell with text.

    We're getting there!

  42. #42
    Registered User
    Join Date
    12-01-2006
    Posts
    55

    Re: Import content from separate Excel files to a single spreadsheet?

    Edit: hmm this doesn't work really well:
    NR = .Range("A" & .Rows.Count).SpecialCells(xlCellTypeLastCell).Row

    Every time I run the macro, more empty lines get copied in.

  43. #43
    Registered User
    Join Date
    12-01-2006
    Posts
    55

    Re: Import content from separate Excel files to a single spreadsheet?

    Hmm any idea? Sorry to keep bugging ;-)

  44. #44
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Import content from separate Excel files to a single spreadsheet?

    No, the syntax is correct and it worked for me. Are the sheets you're testing now notably different?

  45. #45
    Registered User
    Join Date
    12-01-2006
    Posts
    55

    Re: Import content from separate Excel files to a single spreadsheet?

    Please try with this sample attached, importing all yellow cells until line 36 would be ideal.
    As I said, now they get imported correctly, but the next filename+worksheet green line is displayed after F31, rather than after N36.

    (Please ignore the white cells with the text 'ToImport': only the yellow un-hidden cells need to get imported)
    Attached Files Attached Files
    Last edited by paokun; 02-11-2010 at 07:32 PM.

  46. #46
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Import content from separate Excel files to a single spreadsheet?

    Hehe, yep, significantly different. OK. So the visible columns to import are F,M,N and O. We need to check EACH column and use the column with the deepest value for the LR variable.

    We need to do the same thing on the import sheet, too.

    Try these changes, updates marked in red:
    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 02-12-2010 at 08:47 AM.

  47. #47
    Registered User
    Join Date
    12-01-2006
    Posts
    55

    Re: Import content from separate Excel files to a single spreadsheet?

    And it worked!
    I only had to add the dot before Range in the NR variable (.Range) and I got the result I needed.
    Basically now I need to specify all columns I would like to import, but it's just a matter of copying and pasting code to suit my needs.

    Now, to conclude the previous request, how can I have the filename and worksheet name on each line of columns A and B?

    Something like:
    File1 - Sheet1 - Text to import
    File1 - Sheet1 - Text to import
    File1 - Sheet2 - Text to import
    File2 - Sheet1 - Text to import
    File2 - Sheet1 - Text to import

    This way I won't need the green line in between each imported file, I can just filter the filenames using columns A and B.

  48. #48
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Import content from separate Excel files to a single spreadsheet?

    Try this:
    Please Login or Register  to view this content.

  49. #49
    Registered User
    Join Date
    12-01-2006
    Posts
    55

    Re: Import content from separate Excel files to a single spreadsheet?

    Thanks for the quick reply.
    Hmm, this way columns A and B get filled with text to import and then the filename / worksheet name is copied over.

    Please Login or Register  to view this content.
    So now A and B have filename and worksheet name, and CDEF have the text to import. But:

    1. the worksheet name increases on every row (filename is shown correctly);
    2. the text gets imported only from row #2, so the last row in Sheet1 already appears as if it was from Sheet2.

  50. #50
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Import content from separate Excel files to a single spreadsheet?

    Try this:
    Please Login or Register  to view this content.

  51. #51
    Registered User
    Join Date
    12-01-2006
    Posts
    55

    Re: Import content from separate Excel files to a single spreadsheet?

    Hi,

    It worked perfectly, now I have exactly the result I want.
    You're a genius, thanks again a lot for your kind availability!

+ 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