+ Reply to Thread
Results 1 to 7 of 7

macro in cell

Hybrid View

  1. #1
    Registered User
    Join Date
    07-22-2009
    Location
    NYC, NY
    MS-Off Ver
    Excel 2003
    Posts
    22

    macro in cell

    Hi, I was wondering if there was a way to have a Macro associated with a cell. I have 20 cells that have pictures in them, and if you click on the picture, the macro activate. However, there are 20 macros, all of which are the same except for the cell address. If I could make a macro associated with a cell, I could use ActiveCell.FormulaR1C1 to directly edit that cell, and save memory.
    So, is there any way to make a macro associated / part of a cell?

    Okay, so I have posted an example. For each of the 20 cells in the D column (not the 6 cells in row 25) have an UpD## macro, which simply increments them. The macro associated with B1 increments B1 and moves the cursor to D25. I would like there to be only one UpD macro, and it's dependent on what cell you select. If it's possible, I'd also like the UpB1SelectD25 macro not be based in a picture.
    Attached Files Attached Files
    Last edited by nesthead98; 01-26-2010 at 09:39 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: macro in cell

    Hello nesthead98,

    Pictures and other objects are not in the cell. They are displayed over the cell(s) on the Excel Drawing Layer. If the picture is covering the cell then what is the user editing?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    07-22-2009
    Location
    NYC, NY
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: macro in cell

    Right, I currently have 20 small pictures to the right of the text, so it you can see what has happened.
    But I was wondering if there was a way to make a macro associated with a cell (so, clicking the cell would cause a macro to run).

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: macro in cell

    Hello nesthead98,

    It can be done. If you post your workbook, it will be easier and faster to answer your question.

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: macro in cell

    Hello nesthead98,

    The code below has been added to the attached workbook. This will increment the cell count when the picture is clicked.
    Sub UpD03()
      IncCount
    End Sub
    
    Sub UpB1SelectD25()
      IncCount
    End Sub
    
    Sub IncCount()
    
      Dim Shp As Shape
      
        Set Shp = ActiveSheet.Shapes(Application.Caller)
          With Shp
            R = (.TopLeftCell.Row + .BottomRightCell.Row) \ 2
            Cells(R, .TopLeftCell.Column).Value = Cells(R, .TopLeftCell.Column) + 1
          End With
          
    End Sub
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    07-22-2009
    Location
    NYC, NY
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: macro in cell

    Thanks, but I don't seem to understand how it works. Could you explain how I use it?

+ 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