Announcement

Collapse
No announcement yet.

Click In Cell To Run Macro

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Click In Cell To Run Macro



    Is it possible to click in a cell in Excel to run a macro? assign macro to
    cell type thing.

    thanks

  • #2
    Re: Click In Cell To Run Macro

    You can't assign a macro to cell, you could activate it by various worksheet events such as Double Click
    Hope that Helps

    Roy

    New users should read the Forum Rules before posting

    For free Excel tools & articles visit my web site

    If I have helped you and you feel like putting your hand in your pocket please make a donation to Children in Need

    RoyUK's Web Site

    royUK's Database Form

    Where to paste code from the Forum

    About me.

    Comment


    • #3
      Re: Click In Cell To Run Macro

      Thanks for that.

      How do you assign it to a double click event?

      Comment


      • #4
        Re: Click In Cell To Run Macro

        Open the VBE (Alt+F11) and then double click the Sheet in the Project Explorer the code applies to. This is where the code MUST be placed.

        Code:
        Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
        Call MyMacro
        End Sub
        Replace MyMacro with your macro's name
        Hope that Helps

        Roy

        New users should read the Forum Rules before posting

        For free Excel tools & articles visit my web site

        If I have helped you and you feel like putting your hand in your pocket please make a donation to Children in Need

        RoyUK's Web Site

        royUK's Database Form

        Where to paste code from the Forum

        About me.

        Comment


        • #5
          Re: Click In Cell To Run Macro

          thanks so much for that. you have saved my life!!!!

          Comment


          • #6
            Re: Click In Cell To Run Macro

            can you use this method for different macros and different cells etc... if i was to double click in a1 then e1 is pink, if i double click in b1 then f1 is red?? i was trying with an if statement using the activecell range but can get it working.

            Comment


            • #7
              Re: Click In Cell To Run Macro

              is this what you mean?
              Code:
              Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
              Dim i As Integer
              If Target.Cells.Count > 1 Then Exit Sub
              i = Target.Column
              
              Select Case i
              Case 1: ActiveCell.Offset(0, 5).Interior.ColorIndex = 5
              Case 2: ActiveCell.Offset(0, 5).Interior.ColorIndex = 3
              Case 3: ActiveCell.Offset(0, 5).Interior.ColorIndex = 12
              End Select
              
              End Sub
              Hope that Helps

              Roy

              New users should read the Forum Rules before posting

              For free Excel tools & articles visit my web site

              If I have helped you and you feel like putting your hand in your pocket please make a donation to Children in Need

              RoyUK's Web Site

              royUK's Database Form

              Where to paste code from the Forum

              About me.

              Comment


              • #8


                Re: Click In Cell To Run Macro

                thats great.thanks sooooooooooooooo much

                Comment

                Working...
                X