Results 1 to 4 of 4

Thread: Putting a value in a cell by a click

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2005
    Posts
    10

    Putting a value in a cell by a click

    I would like to place a value in a cell when i click the cell. Like say cell A3 when i click it a X should appear. I'm new to VBA. Any help is appreciated.
    Many thanks.

  2. #2
    Fanatic Member ZeBula8's Avatar
    Join Date
    Oct 2002
    Posts
    548

    Re: Putting a value in a cell by a click

    Code:
    Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    Target.Value = "X"
    End Sub
    If you're specifically looking for a cell then you could do this:

    Code:
    Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    If Target = Range("A3") Then
        Target.Value = "X"
    End If
    End Sub

  3. #3
    Hyperactive Member
    Join Date
    May 2001
    Location
    TZI Transition Date
    Posts
    272

    Re: Putting a value in a cell by a click

    Quote Originally Posted by Latoya
    I would like to place a value in a cell when i click the cell. Like say cell A3 when i click it a X should appear. I'm new to VBA. Any help is appreciated.
    Many thanks.
    open a workbook, put this code in a module, run as macro "test1"...should do just what you want...
    VB Code:
    1. Sub test1()
    2. 'PUTS A EMPTY LABEL OVER CELL A3, SIZED AS A3, LINKED TO SUB test2()
    3.     Dim T1, L1, T2, L2, retVal As Long
    4.     If Range("A3") = "" Then
    5.         Range("A3").Select
    6.             L1 = Selection.Left
    7.             T1 = Selection.Top
    8.         Range("B4").Select
    9.             L2 = Selection.Left
    10.             T2 = Selection.Top
    11.         ActiveSheet.Labels.Add(L1, T1, L2 - L1, T2 - T1).Select
    12.         With Selection
    13.             .Name = "Your Label"
    14.             .Placement = xlMoveAndSize
    15.             .Characters.Text = ""
    16.             .OnAction = "test2"
    17.         End With
    18.         Range("A1").Select
    19.         ActiveCell = "Click on Cell A3"
    20.     End If
    21. End Sub
    22. Sub test2()
    23.     If Range("A3") = "" Then
    24.         Range("A3") = "X"
    25.     Else
    26.         Range("A3") = ""
    27.         retVal = MsgBox("Do you want to delete the label control ?", vbYesNo + vbQuestion)
    28.         If retVal = vbYes Then
    29.             ActiveSheet.Shapes("Your Label").Delete
    30.             Range("A1") = ""
    31.         End If
    32.     End If
    33. End Sub
    Last edited by MJBNET; Mar 26th, 2005 at 10:59 AM. Reason: typo in remark - C3 should be A3.

  4. #4
    Addicted Member VbMafia's Avatar
    Join Date
    Sep 2004
    Location
    Pilipinas
    Posts
    177

    Re: Putting a value in a cell by a click

    try to log-on www.vbrad.com many sample there
    " I never did anything worth doing entirely by accident.... Almost none of my inventions were derived in that manner. They were achieved by having trained myself to be analytical and to endure and tolerate hard work."

    " Many of life's failures are experienced by people who did not realize how close they were to success when they gave up. "
    - Thomas Alva Edison-

    In God We Trust

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width