+ Reply to Thread
Results 1 to 16 of 16

VBA Macro to create new worksheet, charts, etc.

  1. #1
    Forum Contributor
    Join Date
    08-15-2005
    Location
    Oklahoma
    MS-Off Ver
    2010, 2013
    Posts
    112

    VBA Macro to create new worksheet, charts, etc.

    Hi,

    I need a macro to create the following worksheets and charts from an Excel data set:

    Three (3) worksheets (already created manually in attached Excel file):

    1. Chart Data.
    (a) Column A in Chart Data is always numbered 1 - 600 (50 years x 12 mos/yr).
    (b) Column I and column Y data sets (from Prod_Month) created in Chart Data. Each data set can be identified and collated with column F in Prod_Month (API) which is unique for each dataset.

    2. Rate vs. Month - plot of Daily Gas (col. Y in Prod_Month) vs. Months (col. A in Chart Data).

    3. Rate vs. Time - plot of Daily Gas (col. Y in Prod_Month) vs. Calender Time (col. B et. al. in Chart Data)

    At a minimum, could someone help me create the Chart Data worksheet from the data in PROD_MONTH? Charting all the columns takes time from Chart Data but any data manipulation macro(s) help.

    Thanks,

    Jim15
    Attached Files Attached Files
    Last edited by VBA Noob; 10-23-2008 at 03:32 PM.

  2. #2
    Forum Contributor pr4t3ek's Avatar
    Join Date
    10-13-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2003 & 2007, 2010
    Posts
    483
    have you tried to create a macro yourself?
    Because this sounds like something you just record and fiddle with and it'll work for you...
    --
    Regards
    PD

    ----- Don't Forget -----

    1. Use code tags. Place "[code]" before the first line of code and "[/code"]" after the last line of code. Exclude quotation marks

    2. Thank those who have helped you by Clicking the scales above each post.

    3. Please mark your post [SOLVED] if it has been answered satisfactorily.

  3. #3
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862
    Below is code to format your data, but before I go any further with this, can you paste this code into your Prod_Month sheet, run it and confirm whether that's how your data should be arranged? If so, then I'll put the chart code together ...
    Please Login or Register  to view this content.
    If this is not right, then let me know where I've gone wrong & I'll take another look. Cheers, MM.
    MatrixMan.
    --------------------------------------
    If this - or any - reply helps you, remember to say thanks by clicking on *Add Reputation.
    If your issue is now resolved, remember to mark as solved - click Thread Tools at top right of thread.

  4. #4
    Forum Contributor
    Join Date
    08-15-2005
    Location
    Oklahoma
    MS-Off Ver
    2010, 2013
    Posts
    112
    Matrix Man - thank you so much! This works great and will save me alot of time.

    What does "Noli nothis permittere te terere" mean?

    Jim15

  5. #5
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862
    you're very welcome Jim ... "don't let the b$%^&ds get you down"

    Of course, this only does the chart data prep; let me know if you'd like me to also code the chart part of your question ...

  6. #6
    Forum Contributor
    Join Date
    08-15-2005
    Location
    Oklahoma
    MS-Off Ver
    2010, 2013
    Posts
    112
    Yes - I would like that. Would you mind defaulting to circles for the data points with a black outline on the circle, please?

    I intend to build upon the work you provided me. There are alot more charts that I can build and your code will certainly help.

    Thanks,

    Jim

  7. #7
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862
    Sure no probs ... in the middle of something so may be an hour or so ...

  8. #8
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862
    ... spoke too soon .. I've just looked at your chart layouts and since in the full set of data you've got 11 groups of data, your charts in this format are going to look a real mess ... are you sure that's how you want them? Perhaps you could run my code in your book and manually configure the charts so I can confirm how you want them to look?

  9. #9
    Forum Contributor
    Join Date
    08-15-2005
    Location
    Oklahoma
    MS-Off Ver
    2010, 2013
    Posts
    112
    You are right - the graphs like this can be very messy but I'm looking for trends in the data so all the data can be plotted, HOWEVER, after thinking about you reply I came up with a better idea which is still partially manual but would save time.

    Would it be feasible to write a macro to select specific data sets in CHART DATA, i.e. I could place my cursor on the cell window which contains the name in ROW A and run the macro which would select or de-select that column of data from the chart? This is automated but would allow more flexibility in plotting. If I plotted the data, I would still manually have to delete that dataset. What do you think?

    Jim15

  10. #10
    Forum Contributor
    Join Date
    08-15-2005
    Location
    Oklahoma
    MS-Off Ver
    2010, 2013
    Posts
    112
    Ignore my second to last sentence, it is confusing. I was referring to the case if all the data was plotted.

    Jim15

  11. #11
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862
    Hi Jim .. yep - that's do-able ... It also allows you to have them all or just those of interest (I knew what you meant )... So if you can manually configure the charts how you want them set up, and reattach your workbook, I'll write a little routine to change the datasets based on which ones a user selects. Just make sure the charts are set up as you want to see them (e.g. I noticed one of them had a logorithmic scale which of course will give an error if zeroes or negative values are in the data). If it really is a log scale, then it will change how I can define the range. Also - can you explain how you use the 1-600 scale in defining the x axis?

  12. #12
    Forum Contributor
    Join Date
    08-15-2005
    Location
    Oklahoma
    MS-Off Ver
    2010, 2013
    Posts
    112
    After thinking a little more, the following might be simpler method for complete chart creation. How about if I copy CHART DATA worksheet as another worksheet say, CHART MOD, and I delete the datasets I don't want plotted? That way, I can manually add or delete the data sets, run your macro one time and the plot is created. This saves me from running the macro each time (I guess you could assign a hotkey to make this easier?). The automated creation of the chart form a dataset would be simpler.

    Yes - the logarithmic scale is correct. That's how the data is presented even though it shows the error.

    The 1 - 600 scales represents months from the start of a well's production. It essentially represents 50 years for a dataset (50 years x 12 months per year).

    Jim

  13. #13
    Forum Contributor
    Join Date
    08-15-2005
    Location
    Oklahoma
    MS-Off Ver
    2010, 2013
    Posts
    112

    Attachment

    Attached as you requested.

    Jim15
    Attached Files Attached Files

  14. #14
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862
    Hi jim ... charting solution is attached. It is triggered when you leave the chart data sheet and it looks to see if any of the well names in row 1 are selected; so if you select the whole of row 1, all well wills be plotted; if you select individual or multiple cells, then those are plotted when you leave the sheet. Of course, you can change whatever triggers the plotting - use a button or whatever suits. Code for the charting bit is below.
    Please Login or Register  to view this content.
    Hope that helps. MM.
    Attached Files Attached Files

  15. #15
    Forum Contributor
    Join Date
    08-15-2005
    Location
    Oklahoma
    MS-Off Ver
    2010, 2013
    Posts
    112

    VBA Macro

    MM,

    I reviewed the VBA Macro and the charting function plots the incorrect date with the data. It should be selecting the Month-YY column immediately before the data instead of after.

    Do you know which line of VBA tells what column to use or can you fix?

    Thanks,

    Jim15
    Jim15

  16. #16
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862
    Hi Jim - yep, sorry about that ... the offending line is:
    Please Login or Register  to view this content.
    ... which of course should be:
    Please Login or Register  to view this content.
    I had the offset to the right instead of the left - doh! Have corrected it for you and it's in the attached.
    Attached Files Attached Files

+ 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