+ Reply to Thread
Results 1 to 9 of 9

VBA selecting relevant data from master sheet to populate new workbooks

  1. #1
    Registered User
    Join Date
    11-12-2014
    Location
    Newcastle, England
    MS-Off Ver
    2010
    Posts
    54

    VBA selecting relevant data from master sheet to populate new workbooks

    Firstly many apologies to HaHoBe and John H Davis for me not replying to my original post in December. I did try them, but couldn't get them to work, must be doing something stupid.

    I've been very busy since and also work then blocked access to ExcelForum.com and ended up doing them manually.

    Please find attached an example of what I am trying to achieve with before and after tabs.
    This example is provided in Excel 2007, but I will need it to work in Excel 2010.

    The range of cells between the values in column A will vary every time, but I need to copy the rows containing the first value in column A down to the row before the next value in column A and each time copying them into cell A8 in a new workbook into and naming it as the value in column and so on until it reaches the last value in column A.

    Many Thanks in anticipation.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: VBA selecting relevant data from master sheet to populate new workbooks

    Try this. Change the "Before" in the first line of code to match the tab name of your source data sheet.

    Please Login or Register  to view this content.

  3. #3
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: VBA selecting relevant data from master sheet to populate new workbooks

    Hi monkeypants

    Here's another approach
    Please Login or Register  to view this content.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  4. #4
    Registered User
    Join Date
    11-12-2014
    Location
    Newcastle, England
    MS-Off Ver
    2010
    Posts
    54

    Re: VBA selecting relevant data from master sheet to populate new workbooks

    Thanks for your replies guys. I've now realised that the reason why it wasn't working previously was that the values in column A were not actually values. That issue resolved now. Schoolboy error!

    Using Jaslakes' approach, I've changed
    With wb1
    .Sheets("Sheet1").Range("A1").PasteSpecial (xlPasteAll)

    to A8, as I want rows 1-7 from the original document to be copied into rows 1-7 of all of the newly created files.

    I've tried with With's and End if's of wb and wb1, but it only seems to be copying over empty data. Obviously I need more training on this

    Thanks in advance.

  5. #5
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: VBA selecting relevant data from master sheet to populate new workbooks

    Hi monkeypants

    Are we still working with the same Sample File as attached to your initial Post?

  6. #6
    Registered User
    Join Date
    11-12-2014
    Location
    Newcastle, England
    MS-Off Ver
    2010
    Posts
    54

    Re: VBA selecting relevant data from master sheet to populate new workbooks

    Yes still making reference to the sample file provided. Your code pretty much does what I'm after, just need finishing touches. Thanks.

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: VBA selecting relevant data from master sheet to populate new workbooks

    Hi monkeypants

    If I understand, this is all you need to do
    Using Jaslakes' approach, I've changed
    With wb1
    .Sheets("Sheet1").Range("A1").PasteSpecial (xlPasteAll)

    to A8, as I want rows 1-7 from the original document to be copied into rows 1-7 of all of the newly created files.
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    11-12-2014
    Location
    Newcastle, England
    MS-Off Ver
    2010
    Posts
    54

    Re: VBA selecting relevant data from master sheet to populate new workbooks

    Apologies for misguiding, I truncated the code to only show the beginning of that section.

    This is what I have:

    With wb1
    .Sheets("Sheet1").Range("A8").PasteSpecial (xlPasteAll)
    fName = myPath & cel.Value & ".xlsx"
    Application.DisplayAlerts = False
    Columns("A:A").Delete
    End With
    With ws
    Rows("1:7").Select
    Selection.Copy
    End With
    With wb1
    .Sheets("Sheet1").Range("A1").PasteSpecial (xlPasteAll)
    ActiveWorkbook.SaveAs Filename:=fName, FileFormat:=xlOpenXMLWorkbook
    ActiveWorkbook.Close
    Application.DisplayAlerts = True
    End With
    Next cel
    Application.ScreenUpdating = True
    End Sub

    When I run this, you can tell that it has tried to copy something into rows 1-7 of the output files, but unfortunately they are empty

  9. #9
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: VBA selecting relevant data from master sheet to populate new workbooks

    Hi monkeypants

    Try this
    Please Login or Register  to view this content.

+ 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. Replies: 2
    Last Post: 03-26-2015, 07:38 PM
  2. VBA Do while loop to capture relevant data from a master sheet?
    By monkeypants in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-12-2014, 11:42 AM
  3. Auto Populate Master Sheet from Multiple Other Workbooks
    By HangMan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-28-2014, 10:22 AM
  4. [SOLVED] Auto-create and name a new tab, and carry relevant data to new tab, from a master sheet
    By teenyjem in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 08-05-2013, 03:38 PM
  5. [SOLVED] VBA to copy relevant data and populate a template sheet
    By kenadams378 in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 01-31-2013, 02:08 PM

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