+ Reply to Thread
Results 1 to 9 of 9

Create new workbook and import data into it

  1. #1
    Registered User
    Join Date
    02-19-2012
    Location
    Nowhere land
    MS-Off Ver
    Excel 2013
    Posts
    13

    Create new workbook and import data into it

    Searching around the forums and I haven't been able to find a solution. I would like to do the following:
    • Create a new workbook with two worksheets - Done
    • Prompt the user to select a text file that contains the data - Done
    • Take the text file and popluate it into one of the sheets in the new workbook - don't know how to do
    • Take the data in the new sheet and create a summary in the remaining sheet in the new workbook - don't know how to do
    • In order to create the summary, it would have to apply formulas to the new workbook - don't know how to do.
    The idea is to have the main workbook that could go out and create a new workbook and do the data analysis. It would be up to the user to save the new workbook. But the bulk of the work will already be done for them.
    Thanks in advance.
    BTW, I don't have any source code to share yet. Just bits for the creation and prompt of the user is complete.

  2. #2
    Valued Forum Contributor
    Join Date
    03-14-2012
    Location
    Arizona USA
    MS-Off Ver
    Excel 2000/2007
    Posts
    408

    Re: Create new workbook and import data into it

    Item:Take the text file and popluate it into one of the sheets in the new workbook - don't know how to do
    _______Let's see a sample of the text file. With this text file, does it matter what data from it goes where?

    Item: Take the data in the new sheet and create a summary in the remaining sheet in the new workbook - don't know how to do
    _______This is possible but it requires the the format of the new sheet to always be the same each time.

    Item: In order to create the summary, it would have to apply formulas to the new workbook - don't know how to do.
    _______It would be better for this project to use a template that gets save after it is filled in. This means that you do not start a new workbook but rather save a template AS some name.

    I would need a sample of the text file and a sample of what the workbook(with analysis) would look like in the end.
    Last edited by Paul; 04-06-2012 at 03:08 PM. Reason: Removed last sentence re: not assisting for free. We are a free, volunteer forum. If you can't do it for free, don't post.

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

    Re: Create new workbook and import data into it

    Yes, there are a myriad of people on the forum you could hire to simply do your project for you if you wish.

    Meanwhile, you can still continue on your own with our tips if you get a little more specific with each question.

    You can turn on the macro recorder and then manually do your entire project from start to end including creating your summary the way you want it to look.

    Then, that source code coupled with your starting TXT file and your final result spreadsheet, the macro could could be tweaked to make it more dynamic and reusable.

    You can learn simple things like how to enter a formula into a cell with VBA using the macro recorder to record you just typing the formula into the cell.

    The recorded code would invariably need tweaking, but it's a great first step for learning the "vba" of anything you already know how to do manually.
    _________________
    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!)

  4. #4
    Registered User
    Join Date
    02-19-2012
    Location
    Nowhere land
    MS-Off Ver
    Excel 2013
    Posts
    13

    Re: Create new workbook and import data into it

    Thank Jerry. I agree, I could just hire someone. However, I am trying help myself and others who may want to also tackle this type of issue in the future. This problem is a little harder than what the macro recorder will handle. I need one workbook to create and control a newly created workbook.
    The text file would be a simple .txt file that has a 13 rows and 5 columns. Data is tab-delimited. Data would just start in A1
    For the formula to place in the destination cell in the newly created workbook, it could be simple as =sum(a1:a13).
    The reason I want to automate this is because I would have to open several files and automation is just plain cool.
    I have attached a sample text file.
    Here is the code for creating a new workbook and asking a user to choose a file
    Please Login or Register  to view this content.
    Attached Files Attached Files

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

    Re: Create new workbook and import data into it

    Heh, almost there. Now, forgetting code for a moment, show me what you would want done with this data. I'm trying simply to get what's in your mind onto a sheet where I can see it, too. Automation follows being able to see the finish line.

    THe macro recorder can easily handle recording YOU doing something simple, then you're right, you have to tweak it (with our help) to make it dynamic and repeatable. That's the point of this exercise.

    This code is yours, with mine derived from the macro recorder recording me actually importing that text file into a sheet. Then I edited it to use the variables you had already designed.

    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 04-09-2012 at 07:32 PM.

  6. #6
    Registered User
    Join Date
    02-19-2012
    Location
    Nowhere land
    MS-Off Ver
    Excel 2013
    Posts
    13

    Re: Create new workbook and import data into it

    Jerry,
    I will not underestimate the power of the macro recorder again! The confusing part is how the macro is referencing the newly creating workbook and hence, manipulating it.
    Your macro work except one line
    Please Login or Register  to view this content.
    It is like it does not know about that sheet. It gives me Application Defined or Object Defined Error. Again, it is confusing how the macro is referencing the newly created book.
    Thanks again!

  7. #7
    Registered User
    Join Date
    02-19-2012
    Location
    Nowhere land
    MS-Off Ver
    Excel 2013
    Posts
    13

    Re: Create new workbook and import data into it

    Well.. that didn't turn out like I wanted it for the formatting. I was trying to highlight
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    02-19-2012
    Location
    Nowhere land
    MS-Off Ver
    Excel 2013
    Posts
    13

    Re: Create new workbook and import data into it

    Ah... I fixed it. I change it to Formula vs. FormulaR1C1
    Please Login or Register  to view this content.
    Thanks again Jerry!

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

    Re: Create new workbook and import data into it

    Good edit. R1C1 means "Row1ColumnA1", which is numeric syntax for A1. With that, you can use that to create a numeric version of the same formula:

    Please Login or Register  to view this content.
    ...which means "column 1" in R1C1 context, not cell 'C1'.

+ 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