+ Reply to Thread
Results 1 to 18 of 18

Macro to populate a specific cell with each item on a list and save

  1. #1
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Macro to populate a specific cell with each item on a list and save

    Hi everyone,

    I currently have a worksheet which populates with data depending on an account number entered on a specific cell. What I'm trying to do is develop a macro which will populate the cell from each item in a list (the list is located on between A1 - A700). Each time the cell is populate with an item going down the list, I'd like the worksheet with the new results saved using the account number and current Year-Month saved in a specific location. Any ideas?

    Thanks very much guys!!

  2. #2
    Forum Contributor
    Join Date
    09-30-2013
    Location
    Toronto, ON
    MS-Off Ver
    Excel 2007
    Posts
    229

    Re: Macro to populate a specific cell with each item on a list and save

    You can save the file with this macro command
    Please Login or Register  to view this content.
    where StrPath contains the drive path name and ends with \.

    It would be easier to figure out the rest if you post your sheet.
    If this helped, please click (*) Add Reputation

  3. #3
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Macro to populate a specific cell with each item on a list and save

    Hi Hectop,

    Thanks for responding. Attached is a sample sheet. So, the way the sheet works is as follows:

    - There is a list of items on the Data sheet from A1 to A10
    - On the Summary page, when one of the items on the Data sheet is entered into cell B1, cells A10 to H16 are automatically populated with data from other data sheets which have not been attached to the sample sheet you have.
    - What I'd like to do, is to develop a macro which will populate each item in the Data sheet cells A1 to A10 into the Summary sheet cell B1.
    - When each item is put into cell B1, cells A10 to H16 populate with their corresponding data. At this time, I'd like the macro to save the Summary sheet using the contents of the cell B1 (which is from the data sheet A1-A10), and beside it say Core, and Summary. If there's a way I can identify a single month in the saved file name for all the items in the Data sheet, that would be great too.

    Thanks very much for you assistance.
    Attached Files Attached Files

  4. #4
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Macro to populate a specific cell with each item on a list and save

    bump. Any help?

  5. #5
    Forum Contributor
    Join Date
    09-30-2013
    Location
    Toronto, ON
    MS-Off Ver
    Excel 2007
    Posts
    229

    Re: Macro to populate a specific cell with each item on a list and save

    Sorry, but can't work on it at work.

  6. #6
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Macro to populate a specific cell with each item on a list and save

    Hectop

    Absolutely. Just wanted to see if anyone else had any thoughts. I look forward to your help with my thanks.

  7. #7
    Forum Contributor
    Join Date
    09-30-2013
    Location
    Toronto, ON
    MS-Off Ver
    Excel 2007
    Posts
    229

    Re: Macro to populate a specific cell with each item on a list and save

    This code should do what you want.
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Macro to populate a specific cell with each item on a list and save

    hectop,

    Thanks very much for your reply! I will try the code out and let you know how it goes. You're help is very much appreciated!!

    If I can ask; you indicated Cells(1, 2) a number of times. Does that means row 1 column 2?

    Also, is there a way the code can be slightly altered to allow me to pick the folder the reports should be saved to in File Explorer?

    Thanks!!
    Last edited by Groovicles; 11-23-2013 at 05:01 PM.

  9. #9
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Macro to populate a specific cell with each item on a list and save

    hi hectop,

    You are a genius. The code works perfectly!! Thanks so much. A question though, how could I change the code so that both the Summary and Data sheets are saved on the new workbooks? Also, is there any way I can get file explorer to pop up so I can select where all the reports should be saved myself?

    Thanks very much!

  10. #10
    Forum Contributor
    Join Date
    09-30-2013
    Location
    Toronto, ON
    MS-Off Ver
    Excel 2007
    Posts
    229

    Re: Macro to populate a specific cell with each item on a list and save

    To copy the Data sheet, copy/modify the lines below the comment "'Copy the Summary sheet to the new workbook"
    There is a way to pop up file explorer. I'll have to find the code and post it tonight. You can try searching in this site. It has been addressed before, just don't remember which question off hand.

  11. #11
    Forum Contributor
    Join Date
    09-30-2013
    Location
    Toronto, ON
    MS-Off Ver
    Excel 2007
    Posts
    229

    Re: Macro to populate a specific cell with each item on a list and save

    This should do everything you want. If you want to change the file extension to save as, you also need to change the FileFilter value

    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Macro to populate a specific cell with each item on a list and save

    Hectop,

    You're fantastic bud. Thanks very much for all your help.

  13. #13
    Forum Contributor
    Join Date
    09-30-2013
    Location
    Toronto, ON
    MS-Off Ver
    Excel 2007
    Posts
    229

    Re: Macro to populate a specific cell with each item on a list and save

    No problem. Just mark is solved and click on Add Reputation.

  14. #14
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Macro to populate a specific cell with each item on a list and save

    Hey Hectop

    The forum won't let me add any more reputations.

    I ran into a bit of an problem. The macro copies the summary and data sheet just fine. However, the copied data sheets retain the original formulas from the template tool where it retrieved all the data which is summarized inthe summary sheet. Is there any way I can keep the values of the cells in the data sheet without having them link back to the original template?

    Thanks!!

  15. #15
    Forum Contributor
    Join Date
    09-30-2013
    Location
    Toronto, ON
    MS-Off Ver
    Excel 2007
    Posts
    229

    Re: Macro to populate a specific cell with each item on a list and save

    I'll check what would be the best way

  16. #16
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Macro to populate a specific cell with each item on a list and save

    Thanks very much. I'm using the original macro you had created so i hope we can add the paste value stuff in that one. Again, I'm try to have the values listed in Summary and Data retained on the new workbook and not point back to the original template.

    This is it with some minor changes (mostly just to add the second worksheet:

    Option Explicit

    Dim iRow As Integer
    Dim sFName, sPath, sWBCur, sWBNew As String
    Dim wsNew As Worksheet

    Sub InterateSht2()
    sWBCur = ActiveWorkbook.Name
    sPath = "C:\stuff" 'Specify the drive\path you want to save to
    For iRow = 1 To 10
    Sheets("Summary").Cells(1, 2).Value = Sheets("Data").Cells(iRow, 1).Value

    'populate A10:H16 here

    'Build the save file name
    sFName = Format(Now(), "yyyy mmm ") & Sheets("Summary").Cells(1, 2).Value & " Summary" & ".XLSX"

    'Create a new workbook that will contain the new summary sheet
    Workbooks.Add
    sWBNew = ActiveWorkbook.Name

    'Copy the Summary sheet to the new workbook
    Windows(sWBCur).Activate
    Sheets(Array("Summary", "Data")).Copy Before:=Workbooks(sWBNew).Sheets(2)

    'Save the new workbook & close
    Windows(sWBNew).Activate
    ActiveWorkbook.SaveAs Filename:=sPath & sFName
    Windows(sFName).Close
    Next iRow
    End Sub
    Last edited by Groovicles; 11-26-2013 at 03:30 PM.

  17. #17
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Oshawa
    MS-Off Ver
    Excel 2010
    Posts
    660

    Re: Macro to populate a specific cell with each item on a list and save

    Hi everyone, sorry I had to bump this.

    Hectop has been incredibly giving in helping me build the VBA code listed above. And while I would normally wait for his response, this code in a modified for is being used for a work project I'm on.

    I have a template built which populates certain cells based on an identifer number entered in a specific cell. Hectop created the VBA code listed above which runs a list of these identifier numbers through my template, and then copies the summary and data pages onto a new workbook and saves them based on a specific naming convention; bloody brilliant.

    What I'm trying to do how is adjust Hectop's code to have the values generated on the summaries pasted on as values rather than with formulas linking them back to the original template. I understand the PasteSpecial code would be used, but I'm not sure how to incorporate it. Like most of us, Hectop is a busy guy. I would normally wait for the response from anyone who would be helping me, but this help is related to a work project I'm on.

    Thanks very much for your help, everyone!!

  18. #18
    Forum Contributor
    Join Date
    09-30-2013
    Location
    Toronto, ON
    MS-Off Ver
    Excel 2007
    Posts
    229

    Re: Macro to populate a specific cell with each item on a list and save

    Can you post a sheet with the references/formulae?

+ 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: 08-02-2013, 08:04 AM
  2. Replies: 0
    Last Post: 07-11-2013, 02:08 AM
  3. Save Multiple Files based on List AND Populate a Cell with value
    By aetedford in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-09-2013, 04:25 PM
  4. Replies: 3
    Last Post: 09-26-2012, 01:29 PM
  5. Cell Color changes when specific item is selected in List.
    By nukecity83 in forum Excel General
    Replies: 4
    Last Post: 07-12-2009, 06:24 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