+ Reply to Thread
Results 1 to 5 of 5

Copying shapes from one sheet to another for Game

  1. #1
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Copying shapes from one sheet to another for Game

    Okay, working on developing a game. This is a simpler template.

    Mechanics: Sheet “Random” shuffles the cards. There are 5 shapes (in final version, there will be 27). Each card will have between 1 to 3 of a specific shape on it (Cards will only have 1 shape, not different shapes). Players will double click on a cell to clear the shapes from that cell. Clicking the “Deal” button will replenish the “empty” cells with fresh cards in order of rank from “Random” using VLOOKUP.

    Two Issues (Okay, maybe more than two), let’s just tackle the first.
    What’s the best way to copy shapes (these are shapes from the “Insert Shapes” menu) from “pics” to the appropriate cells

    I have a VLOOKUP finding the shape name and number of times to paste the shape into the cell. . I think my CASE code will position them properly once they are there. I named the cells in which the pics are located as a defined name the same as the pic name (if that helps). For example pics!A1 is pic_1 and pic_1 is located in A1.
    Here’s the code I have so far.

    Please Login or Register  to view this content.
    See Attached. Thanks in advance. I am taking this step by step so I can learn as I go.
    Attached Files Attached Files
    Last edited by ChemistB; 11-12-2014 at 10:13 AM.
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  2. #2
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Copying shapes from one sheet to another for Game

    Hi,

    Please look at my attached file, maybe this is what you expect ?
    I have comment my code (all in module2), so there is an explanation of what the next lines will do.
    Please tell me what you think.

    Regards
    Attached Files Attached Files
    1. I care dog
    2. I am a loop maniac
    3. Forum rules link : Click here
    3.33. Don't forget to mark the thread as solved, this is important

  3. #3
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Copying shapes from one sheet to another for Game

    Wow, thanks Kare. Seems to work great. I will dissect it and get back to you. Fantastic.

  4. #4
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Copying shapes from one sheet to another for Game

    Hi,

    Welcome to the wacky world of shapes. You may not need the 'Named Ranges' for your pictures. Although Excel allows duplicate 'Shape Names' on a sheet, it is something I try to avoid. When I create new shapes I either number them sequentially or name them according to some algorithm (e.g. 'myShapeC10' for a shape anchored to cell 'C10').

    Attached are a few Shape Utility functions that should help you now and in the future. All were tested successfully with your worksheet:
    a. GetActiveShapeAttributes() - Gets the name, coordinates and other attributes associated with a Shape.
    b. RenameActiveShape() - Renames a Shape.
    c. LoopThroughShapes() - Gets attributes for all Shapes on the Active Sheet. The output is put on Sheet 'Log' (which is created if it doesn't already exist.
    d. DeleteAllShapesOnActiveSheet() - Deletes all Shapes on the Active Sheet (including Charts). Comments attached to cells are NOT DELETED.
    e. DeleteSpecialShapesOnActiveSheet() - Deletes all Shapes on the Active Sheet that start with a SPECIAL naming convention.
    f. CopyShapesToNewSheet() - Example of how to copy Shapes (adapted from your Deal() macro)

    Here are a couple of other comments about your code which may help you in the future:
    a. I noticed you didn't use 'Option Explicit' at the top of your module. To prevent typos from ruining days and weeks of work 'Option Explicit' is NEEDED at the top of each code module. This prevents errors caused by missspellings and FORCES every variable to be DECLARED (e.g. dim i as Integer). http://www.cpearson.com/excel/DeclaringVariables.aspx

    b. When declaring global variables you should probably identify them as being global .e.g.
    Please Login or Register  to view this content.
    That way you know to look at the top of a module to find it's definition. To the best of my knowledge the KEYWORD 'Global' is archaic and is only present for backward compatibility. You should probably replace it with 'Public'.

    Lewis

    ------------------
    Code follows (ordinary Module code such as 'Module1'):
    Please Login or Register  to view this content.
    Last edited by LJMetzger; 11-12-2014 at 12:09 PM.

  5. #5
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Copying shapes from one sheet to another for Game

    Thanks Lewis!
    As my primary aim at creating this game is to increase my VBA skills, your specific subroutines, once examined, should help me greatly. I appreciate your comments on Explicit and Public variables too. Hats off to you.

+ 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. [SOLVED] Delete Buttons made from shapes when copying sheet to new workbook
    By Bflare in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-27-2014, 09:44 AM
  2. Copying Shapes using Formulas
    By ODmac in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-22-2013, 09:39 AM
  3. Deleting Shapes and Copying between variable worksheets
    By bhenderson in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-20-2012, 08:52 PM
  4. VBA copying shapes between workbooks stops
    By Per Almgren in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-16-2012, 07:52 AM
  5. [SOLVED] Game score without game being played
    By Sheila in forum Excel Formulas & Functions
    Replies: 14
    Last Post: 05-17-2005, 07:06 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