+ Reply to Thread
Results 1 to 35 of 35

Insert Diamond Shape for every Row and add cell value to each shape

  1. #1
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Insert Diamond Shape for every Row and add cell value to each shape

    I have an excel spreadsheet that has data in columns A through D. In Column D, there are dates in the format "MM-DD-YYYY". What I want the coding to do, is for every value in column D to insert a DIAMOND shape in the next column over (column E) and then to insert the text in D2 into it's respective shape. This needs to be a loop since the amount of rows vary all the time.

    Please see the attached workbook for an example of how the data is set up. Need ASAP

    Thanks!
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Re: Insert Diamond Shape for every Row and add cell value to each shape

    Can anyone please help me with this? Need help ASAP!!

  3. #3
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Insert Diamond Shape for every Row and add cell value to each shape

    Are you sure about your requirement?
    - add approximately 18,490 diamond shapes
    - add the text of the D column for the specific row to the shape (and not always D2)
    If you like my contribution click the star icon!

  4. #4
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Re: Insert Diamond Shape for every Row and add cell value to each shape

    Hey Ollie,

    Yes, I am positive about the requirement. I need code that will loop through and ends once one of the cells in column D is blank, there could be 1,000 rows or there could potentially be 18,000 just like this case. So, for every row that has data in Column D, complete the following:

    1. Insert a diamond shape to column E for every row
    2. Add the text in column D for each cell into its respective shape
    3. Then fit the shape to each cell.

    Please let me know if you have any further questions! Thanks for any help!

  5. #5
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Insert Diamond Shape for every Row and add cell value to each shape

    Ok. Try the following code

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Re: Insert Diamond Shape for every Row and add cell value to each shape

    Hey Ollie,

    This works well. However, Once the code gets to the last cell in the used range, it loops back to the first value in column D. I need the code to stop once a value in Column D = ""

  7. #7
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Insert Diamond Shape for every Row and add cell value to each shape

    The loop is from row 2 to the last row in column A. There is no loop back in the code! Do you want the process to stop when an empty cell in column D is encountered?

    Assuming that is what you want, the revised code is below

    Please Login or Register  to view this content.
    Last edited by OllieB; 01-10-2013 at 02:30 PM. Reason: added the code

  8. #8
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Re: Insert Diamond Shape for every Row and add cell value to each shape

    Yes, I need the code to stop when an empty cell in Column D is encountered. I also need the font to be Arial as well as font size 6

  9. #9
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Insert Diamond Shape for every Row and add cell value to each shape

    As ordered

    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Re: Insert Diamond Shape for every Row and add cell value to each shape

    Hey Ollie,

    You were able to help me tremendously with adding date values to shapes and having the shapes loop through until the end of the used range. That was GREAT!

    Now, I have a much FUNNER task...

    The shapes that were added (of which you were so kind to help with!), now have the dates in them with the format "MM/DD". I have added a table in a different tab named "Slides" that has the following headers: Q1 2013, Q2 2013, Q3 2013, Q4 2013, etc (up to Q4 2016).

    I have added an additional column that will have these values associated to the record which is also associated with the shape.

    IF the record contains the value "Q1 2013", then I want the EXACT shape that is within this record to find the "Q1 2013" within the table in the other tab and position this shape directly below "Q1 2013". I need this to be done for EVERY RECORD. However, there is a catch. There is ANOTHER condition that needs to be added. There will be another field within the record that will have either A, B, C, D, E, or F. IF the record falls within "Q1 2013" AND "D", THEN go to Column with "Q1 2013" within the table and move DOWN the amount of rows to get to "D". I need this shape to be placed in the position of "Q1 2013" & "D" within the table location.


    As of right now, I believe the amount of records are around 100. So it's not a huge load.

    Please see the workbook I have attached for the example. I need this ASAP as I need to push this report out very quickly
    Attached Files Attached Files

  11. #11
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Insert Diamond Shape for every Row and add cell value to each shape

    Why don't you just create the shapes on the Slides worksheet, as opposed to creating the shapes on the task worksheet and then moving them? You would only need to add a Slides worksheet reference for the .Shapes.Add statement and calculate the position parameters based on the columns and rows on the Slides worksheet.

    I am also not sure about
    a. placing both the diamond and text box in the small space available for a quarter on the slide worksheet (how would you like to see them positioned?);
    b. how should multiple diamonds and multiple textboxes need to be positioned within the same quarter?

  12. #12
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Re: Insert Diamond Shape for every Row and add cell value to each shape

    Thanks Ollie for the response!

    Well, I am not sure how to do a reference and what you are saying...

    I figured I would add a step to ensure the diamonds and text boxes were for the CORRECT record.

    I am also not sure about
    a. placing both the diamond and text box in the small space available for a quarter on the slide worksheet (how would you like to see them positioned?);
    b. how should multiple diamonds and multiple textboxes need to be positioned within the same quarter?


    a) For now, I am only worried about getting the shapes to be able to be positioned to the CORRECT spot. Once the shapes have been positioned properly, then I can worry about the text boxes...But I think the best way would be to group the two shapes that are within the same record together, and then have that groupbox positioned accordingly to the proper Quarter and proper classificaiton on the "Slides" tab.
    - However, ideally it would be great if the shapes were offsetted to account for the monthly cadence.
    - For example: Since Q1 includes - January, February, March THEN
    have the shapes that are part of January be positioned slightly to the left of February's, and February's slightly to the left of March, etc..

    b) I believe that once the shapes have been positioned to the proper Quarter, then the USER will have to go in and manually position them accordingly since the text boxes vary with Character lengths. Some text boxes will actually have up to 150 characters. So I think once the shapes have been positioned correctly, then the USER will go in and manually position them. The thing I want to avoid, are all the shapes being positioned on top of one another b/c then the user wont be able to distinguish what textboxes are supposed to be with which Diamond (I think Grouping will solve this issue though, but you never know).

    I hope that answers your questions...please let me know ASAP if they didnt, b/c once again I need to push this report out ASAP! You're the BEST Ollie!

  13. #13
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Insert Diamond Shape for every Row and add cell value to each shape

    Which date is used to determine the calendar quarter? When I look at the Task sheet I am not able to figure it out. I need this information to position the shape properly within the calendar quarter slot in case there are multiple tasks within a quarter (see answer a).

  14. #14
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Insert Diamond Shape for every Row and add cell value to each shape

    Ok, have a look at the attached workbook. Routine CreateShapes() in module OllieB. I have taken some liberties in making a few changes. Per quarter you now have three horizontal slots (i.e. the months) and per horizontal slot you have two vertical slots in case two tasks end in the same month. For the 3rd and further the task will be positioned one line down and slightly to the right of the previous task.
    Attached Files Attached Files

  15. #15
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Insert Diamond Shape for every Row and add cell value to each shape

    New version attached. I forgot about the requirement to group the diamond and textbox shapes.
    Attached Files Attached Files

  16. #16
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Re: Insert Diamond Shape for every Row and add cell value to each shape

    Wow Ollie this is absolutely AWESOME! This is perfect, exactly what I am looking for. In order for me to transfer this code and to edit the correct columns to match up to the report I will be utilizing and the used range of data that I will be using, can you please put your code in maybe a word document highlighting in a certain color for let's say Classification, Finish Date, and Description that I may need to edit. For instance, within your code if my Finish Date or Description were in different columns, where in your code do I need to edit? Also, if the Classification name is a text string instead of an "A" or "B", as long as that text string is in the slides tab in column A for the lookup, will the code still find the correct table to paste the shapes in?

    One last request , I think it would also be extremely helpful if the text boxes were able to have the Chr(13) after around 50 characters. That way anything over 50 characters would basically do a wordwrap to a multi-line. Ollie, you are the MAN and have made my life so much easier!

  17. #17
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Insert Diamond Shape for every Row and add cell value to each shape

    Hi bcn,

    Please find attached a new version!

    I have added the request to allow limiting the maximum width of the textbox. Your other request (i.e. describe what needs to be changed when you copy the code to the target workbook) I have addressed in a different manner than requested. I have not written a WORD document but I have made nearly all column and worksheet references parameter driven. All these parameters are declared at the top of the module as private constants.

    To be specific:

    Please Login or Register  to view this content.
    When you copy&paste the code into the real workbook, this section should hold all the parameters that may need adjusting. I hope the parameter names and comments are sufficient to understand the meaning of them. The actual coding is quite generic in nature, so for example changing the number of rows on the task worksheet, number of calendar quarters on the output slide or the number of classification codes (including the length of the classification codes itself) are all coded in a dynamic/generic manner and no code adjustments should be necessary.
    Attached Files Attached Files

  18. #18
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Re: Insert Diamond Shape for every Row and add cell value to each shape

    Hey Ollie,

    You are absolutely awesome. My new favorite pen pal! haha

    Thank you for making your code parameter driven as this will be EXTREMELY beneficial in the future so there is
    very low maintenace, if any required. When I transfered the code to the target workbook and changed your declarations
    to reflect the columns associated, my first attempt running the code gave me a compile error so I went into my references
    and saw that I needed to add "Microsoft Scripting Runtime". I tried running code again and I received a run-time
    error, more specifically:

    Run-time error '457': This key is already associated with an element of this collection

    The line of code that fails at is line 119:
    dctClassification.Add Trim$(.Cells(lngRowNumber, gstrOClassificationCodeColumn).Value), lngRowNumber

    Any thoughts?

  19. #19
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Re: Insert Diamond Shape for every Row and add cell value to each shape

    Actually, scratch my last comment about line 119. I saw your comment and I had to unmerge column A on the Slides tab. Once I changed the merged range to column B the code ran up until line 154 with the run-time errror:

    Run-time error '424': Object required


    I tried deciphering..but to no avail

  20. #20
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Insert Diamond Shape for every Row and add cell value to each shape

    Yes, I do. The routine loops through all rows on the Slides output worksheet and looks at at specific column for non-blank values (in the old situation column "A"). In order for this to work I had to change the merged title just above each section to start in column B

    See coding comment:
    Please Login or Register  to view this content.

  21. #21
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Insert Diamond Shape for every Row and add cell value to each shape

    I don't use line numbers. What code is on that line?

  22. #22
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Re: Insert Diamond Shape for every Row and add cell value to each shape

    Yup, I did the unmerge but now have a failure at line 154 see above right before your last comment

  23. #23
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Insert Diamond Shape for every Row and add cell value to each shape

    Like I said in post #21, I do not use line numbers; what code is on that line?

  24. #24
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Re: Insert Diamond Shape for every Row and add cell value to each shape

    Code is on line 154-155:

    Set objCalendarQuarter = dctQuarters(Trim$(.Cells(lngRowNumber, gstrCalendarQuarterColumn).Value) _
    & "|" & Trim$(.Cells(lngRowNumber, gstrIClassificationCodeColumn).Value))

    If you look right under the Help dropdown menu, you will see where in the VBE it tells you where your cursor is on which line and what column in the code.

  25. #25
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Insert Diamond Shape for every Row and add cell value to each shape

    Ok. easy problem. this means that it encountered a quarter and classification code for a task that do not exist on the output slide. Do you want me to change the code to give you a proper error message for this, or was this a one-off problem?

  26. #26
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Re: Insert Diamond Shape for every Row and add cell value to each shape

    Hey Ollie,

    I did not have Q4 2015 through Q4 2016 listed in the Slides tab but I did have data for those Quarters. I added these quarters and years to the slides tab, ran the code and still received the same run-time error at same line. I then ensured that all of my classification text in column A on the slides tab match the entries in the records on the Task tab - they did match. However, I still get the same run-time error: Object required

  27. #27
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Insert Diamond Shape for every Row and add cell value to each shape

    You did copy the CLASS module to the new workbook as well, right? New version, with improved error handling attached.

    Coding in the main routine has been changed for this. Also make sure that your instance is set to report all errors, i.e. Tools/Options/General - break on all errors
    Attached Files Attached Files

  28. #28
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Re: Insert Diamond Shape for every Row and add cell value to each shape

    Hey Ollie,

    I am still receiving the same error at the same line. Yes, I do have the class module as well. Your new msgbox if statement wasn't reached...I did go into Tools > Options > General - Break on All Errors. So that is done...

    Just FYI..

    - Classification column
    * This column is now Column "C" and is column header "Workstream"
    * Column includes text strings that are equal to the text strings in Column A on the slides tab

    - Description column
    * This column is now Column "M" and actually doesn't have a header. There is a formula in
    this column "=MID(E2,8,1000)" . This is the value that goes into the textbox

    - Finish Date column
    * This column is now Column "F" and is column header "Finish"

    - Task type column
    * This column is now Column "J" and doesn't have a header

    - Calendar Quarter column
    * This column is now Column "N" and doesn't have a header

  29. #29
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Insert Diamond Shape for every Row and add cell value to each shape

    My mistake. Because we have no "on error resume next" the messagebox is not reached. Revised version to address that problem is attached
    Attached Files Attached Files

  30. #30
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Re: Insert Diamond Shape for every Row and add cell value to each shape

    SPECTACULAR! Worked!

    Can we get the text boxes to move down a little bit? I would essentially like for the top of the text box to barely be touching the bottom of the diamond.

  31. #31
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Insert Diamond Shape for every Row and add cell value to each shape

    So what was the problem?

    Yes, we can. There is a line that reads something like (I am not behind my pc right now) lngT_ShapeTop=lngD_ShapeTop+22. Change the value 22 to 36 or so

  32. #32
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Insert Diamond Shape for every Row and add cell value to each shape

    Just realizing that if you move the textbox outside of the diamond the positioning of the next diamond for the same month will overlap. Either you change the code or keep it as it is currently.

  33. #33
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Re: Insert Diamond Shape for every Row and add cell value to each shape

    Let's discuss tonight...I have to go somewhere as well. I have to think about this...I really dont want you to have to change any code.

    I'll be back on in about 7 hours...thanks Ollie.

  34. #34
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Re: Insert Diamond Shape for every Row and add cell value to each shape

    Hey Ollie,

    I am going to show my colleagues tomorrow, and get their opinion on how everything is set up right now. So I will keep you posted and will let you know by tomorrow night! Again, thanks so much for your help! You have been awesome.

  35. #35
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Re: Insert Diamond Shape for every Row and add cell value to each shape

    Hey Ollie,

    I know it has been some time since I have added anything to this thread. However, I finally have results on how to proceed with this task! The code has worked great, and I have to say I have had A LOT of comments on how awesome the code is! The ONLY issue is the final product which is going into a powerpoint slide. What I've found is it is extremely difficult to maintain the shapes of the diamonds and the text within the diamond to transfer into a powerpoint slide. The diamonds change shape to appear much smaller than the actual object in Excel, and this actually creates A LOT of work for me. Is there any way to have the end result take every shape and put them straight into a powerpoint, and then the user can edit the placements in the slide itself? This would eliminate the issues I am having when I am doing the transfer from spreadsheet to powerpoint as the shapes do not maintain their structure from excel. Any thoughts?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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