+ Reply to Thread
Results 1 to 6 of 6

Clicking on a cell...

Hybrid View

  1. #1
    Registered User
    Join Date
    01-02-2008
    Posts
    8

    Clicking on a cell...

    Hi
    Is it possible to initiate a formula by clicking on a cell? I can't seem to find any information on doing so...
    Thanks

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Not sure exactly what you mean...please elaborate.
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Maybe with an event macro. What is your formula or scenario

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  4. #4
    Registered User
    Join Date
    01-02-2008
    Posts
    8

    Sorry - that wasn't well put...

    Hi
    A very basic example would be if I wanted to show the result (in B3) of B1*B2 by clicking on the * in B4, or B1+B2 by clicking on the + in B5... if that makes sense.....

    _A B C D
    1 ...5.....
    2 ...3.....
    3 .........
    4 ...*....
    5 ...+....

    Thanks
    Last edited by KennytheFish; 01-04-2008 at 04:25 PM.

  5. #5
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887
    Hi Kenny,

    The following macro should work for you. Right-click on the sheet tab for which you want this functionality and choose View Code. Copy and paste the code below into the VB screen that appears. Close the VB screen and test.
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
        If Intersect(Range("B4:B5"), Target) Is Nothing Then
            Exit Sub
        Else
            If Range("B1") = "" Or Range("B2") = "" Then
                MsgBox "Missing value in cell B1 or B2", vbOKOnly, "Oops!"
                Range("B3").Select
                Exit Sub
            Else
                Select Case Target.Text
                    Case Is = "*"
                        Range("B3").Value = Range("B1").Value * Range("B2").Value
                    Case Is = "+"
                        Range("B3").Value = Range("B1").Value + Range("B2").Value
                    Case Else
                        MsgBox "Invalid operand"
                End Select
            End If
        End If
        Range("B3").Select
    End Sub
    This works by double-clicking one of the two cells (B4 or B5) after inputting numbers into B1 and B2. If either B1 or B2 is blank, the macro will let you know and then quit before performing any math. If you double-click a cell other than B4 or B5, the macro will quit and the sheet will act normally (putting you into the cell you double-clicked).

    UPDATED CODE, was handling events in the wrong order.
    Last edited by Paul; 01-05-2008 at 01:08 AM.

  6. #6
    Registered User
    Join Date
    01-02-2008
    Posts
    8

    Thanks

    Thanks for the trouble of doing that, its really helped

+ 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