+ Reply to Thread
Results 1 to 13 of 13

Pasting data to a master excel sheet

  1. #1
    Forum Contributor
    Join Date
    09-19-2017
    Location
    London
    MS-Off Ver
    2015
    Posts
    169

    Pasting data to a master excel sheet

    Hi!

    I have around 50 Excel Workbooks in one Folder, and one Excel Workbook may contain around 20 to 40 Excel sheets. My issue is that I want to paste link of one cell range which its position is all the same (H4) in all Excel Worksheets and in all Workbooks to one master Excel sheet. The things are:

    1. All the sheets denote different months, meaning the value in H4 symbolizes the same data but from different month.
    2. The H4 values will then have to be pasted (paste link) to different cell ranges in specific row, i.e. H4 values from 12 sheets from Workbook A will have to be pasted starting from I2 to T2.

    May I know where to start? Right now I only managed to loop through all the Excel files but I'm quite lost on what to do next. What I know is that:

    1. Have to loop through all Excel files in the folder
    2. Have to loop through all sheets to copy every H4
    3. Have to open Master Excel file
    4. Have to place the specific copied H4 values in specific row, one sheet from one Workbook in a cell in one row, another sheet from the same Workbook in another cell but the same row.

    Can anyone give me some enlightenment? Thank you in advance.

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,619

    Re: Pasting data to a master excel sheet

    Make step 3 before 1 and 2
    and then you can combine step 4 with step 2.
    This shall be enough.


    If that's not enough please attach a SMALL sample Excel workbooks (Master and sample data). Please don't attach a picture of one (no-one will want to re-type all your stuff before starting).

    1. Make sure that your sample data are truly REPRESENTATIVE of your real data. The use of unrepresentative data is very frustrating and can lead to long delays in reaching a solution.

    2. Make sure that your desired solution is also shown (mock up the results manually).

    3. Make sure that all confidential information is removed first!!


    Unfortunately the attachment icon doesn't work at the moment. So, to attach an Excel file you have to do the following: Just before posting, scroll down to Go Advanced and then scroll down to Manage Attachments. Now follow the instructions at the top of that screen.
    Best Regards,

    Kaper

  3. #3
    Registered User
    Join Date
    10-19-2017
    Location
    Timashevsk, Russia
    MS-Off Ver
    Professional Plus 2010
    Posts
    8

    Re: Pasting data to a master excel sheet

    Hi,
    Can you clarify:
    -Is link you mentioned a hyperlink or a formulae?
    -When we come to next workbook in a loop, we shift to next row of master file, right?

  4. #4
    Registered User
    Join Date
    10-19-2017
    Location
    Timashevsk, Russia
    MS-Off Ver
    Professional Plus 2010
    Posts
    8

    Re: Pasting data to a master excel sheet

    Kaper says the right thing
    Make step 3 before 1 and 2
    and then you can combine step 4 with step 2.
    As I understood, your algo would be like this:
    1. Open master file
    2. Loop through Excel files with iterator i which stands for current row of master file. Both current file and master file should be opened at the same time.
    2.1 Open current Excel file
    2.2 Loop through Workbook.Sheets collection using iterator j which stands for current column in master file (current cell).
    2.2.1 Copy H4 value from 'j'th sheet
    2.2.2 Paste it into master_sheet.Cells(i, j)
    2.3 Close current Excel file properly!
    3. Close master file properly

    Ask if some extra help with code needed. And please post final code here as a solution.
    Last edited by bansgoo; 10-19-2017 at 04:31 AM.

  5. #5
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,619

    Re: Pasting data to a master excel sheet

    I'd just add
    2.1.1 Write current Excelf file name into master_sheet.Cells(i, 1)
    and then change
    2.2.2 Paste it into master_sheet.Cells(i, j+1)
    or may be as output was expected in
    I2 to T2
    7 and 8 (if i and j starts from 1) shall be used respectively

  6. #6
    Forum Contributor
    Join Date
    09-19-2017
    Location
    London
    MS-Off Ver
    2015
    Posts
    169

    Re: Pasting data to a master excel sheet

    Hi Kaper and Bansgoo,

    Hereby I attached the example of Excel Workbook which has the data along with the Master Excel.

    What I currently have is this:

    Please Login or Register  to view this content.
    Your help is really appreciated. Thanks!
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    09-19-2017
    Location
    London
    MS-Off Ver
    2015
    Posts
    169

    Re: Pasting data to a master excel sheet

    Quote Originally Posted by bansgoo View Post
    Hi,
    Can you clarify:
    -Is link you mentioned a hyperlink or a formulae?
    -When we come to next workbook in a loop, we shift to next row of master file, right?
    Hi Bansgoo,
    1. It's a formulae, I have shown an example in my zipped file.
    2. Yes indeed, and same goes to when we shift to next sheet in the same workbook, we go to the next column but in the same row.

  8. #8
    Registered User
    Join Date
    10-19-2017
    Location
    Timashevsk, Russia
    MS-Off Ver
    Professional Plus 2010
    Posts
    8

    Re: Pasting data to a master excel sheet

    What help do you ask for, exactly? What steps of given algorithm are difficult for you?
    Regarding the code you've posted, I have only 1 question
    Please Login or Register  to view this content.
    Why do you do that? This line doesn't do anything as for what I know.
    The rest of the code looks fine I think. Just create another Excel Application for master file and open it. Then write another loop inside of exising one and you'll be fine

  9. #9
    Forum Contributor
    Join Date
    09-19-2017
    Location
    London
    MS-Off Ver
    2015
    Posts
    169
    Quote Originally Posted by bansgoo View Post
    What help do you ask for, exactly? What steps of given algorithm are difficult for you?
    Regarding the code you've posted, I have only 1 question
    Please Login or Register  to view this content.
    Why do you do that? This line doesn't do anything as for what I know.
    The rest of the code looks fine I think. Just create another Excel Application for master file and open it. Then write another loop inside of exising one and you'll be fine
    This code was actually given by my superior and he asked me to continue from here. I believe the line is there to justify the line below it. Since I'm new with VBA, I still dont have any idea how to apply looping.

  10. #10
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,619

    Re: Pasting data to a master excel sheet

    As for my point of view - you can delete this line. It does nothing useful.

    And kind reminder about forum https://www.excelforum.com/forum-rul...rum-rules.html

    Don't quote whole posts -- it's just clutter. If you are responding to a post out of sequence, limit quoted content to a few relevant lines that makes clear to whom and what you are responding

    For normal conversational replies, try using the QUICK REPLY box below.

  11. #11
    Forum Contributor
    Join Date
    09-19-2017
    Location
    London
    MS-Off Ver
    2015
    Posts
    169

    Re: Pasting data to a master excel sheet

    Thank you for the reminder, Kaper.

  12. #12
    Registered User
    Join Date
    10-19-2017
    Location
    Timashevsk, Russia
    MS-Off Ver
    Professional Plus 2010
    Posts
    8

    Re: Pasting data to a master excel sheet

    If you're waiting that somebody will write the code entirely for you, you might be waiting for a long time.
    I'll give you some clues. Here's what I've advised you to do:
    1. Open master file
    2. Loop through Excel files with iterator i which stands for current row of master file. Both current file and master file should be opened at the same time.
    2.1 Open current Excel file
    2.2 Loop through Workbook.Sheets collection using iterator j which stands for current column in master file (current cell).
    2.2.1 Copy H4 value from 'j'th sheet
    2.2.2 Paste it into master_sheet.Cells(i, j)
    2.3 Close current Excel file properly!
    3. Close master file properly
    You should write and execute this procedure in master file. So it will be open by default. So you don't need to write the step 1.
    Step 2 is actually just Do While <...> Loop cycle iterating on files in the folder. You've got that cycle in code but you haven't got a counter variable which is necessary to enable writing each file in different row. It will look like this:
    Please Login or Register  to view this content.
    Step 2.1 is there already in code, inside the loop
    Step 2.2 is much the same as step 2. It's a loop inside a loop. Loop on j can just go through all the sheets. As sheets have indexing, we can use For loop here. Both loops look like this:
    Please Login or Register  to view this content.
    Hope that helps
    Last edited by bansgoo; 10-20-2017 at 03:11 AM.

  13. #13
    Forum Contributor
    Join Date
    09-19-2017
    Location
    London
    MS-Off Ver
    2015
    Posts
    169

    Re: Pasting data to a master excel sheet

    Thank you so much, Bansgoo!

    Your thorough explanation will help me. Will post the code if I have done or if I have issue with it.

+ 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] VBA - value is not pasting in master sheet
    By shido in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-13-2015, 04:28 PM
  2. Copying/Pasting Data from All Files in Folder to Master Sheet According to Headers
    By sdwhiteh in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-22-2015, 01:23 PM
  3. Excel 2007 - VBA to copy data from one sheet and pasting to another sheet
    By abhimails in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-29-2014, 07:40 AM
  4. Replies: 1
    Last Post: 09-15-2014, 01:03 PM
  5. Copy Data from a fixed form of data sheet into a master excel sheet.....
    By sirimhk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-18-2012, 08:48 AM
  6. Opening 4 excel files, copying set table data and pasting into "master file".
    By Belloni in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-29-2012, 09:50 AM
  7. [SOLVED] Copy and pasting specific sheet data to a master worksheet
    By simora in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-09-2005, 01:06 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