|
-
Mar 25th, 2005, 08:24 PM
#1
Thread Starter
New Member
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.
-
Mar 25th, 2005, 10:05 PM
#2
Fanatic Member
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
-
Mar 26th, 2005, 12:21 AM
#3
Hyperactive Member
Re: Putting a value in a cell by a click
 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:
Sub test1()
'PUTS A EMPTY LABEL OVER CELL A3, SIZED AS A3, LINKED TO SUB test2()
Dim T1, L1, T2, L2, retVal As Long
If Range("A3") = "" Then
Range("A3").Select
L1 = Selection.Left
T1 = Selection.Top
Range("B4").Select
L2 = Selection.Left
T2 = Selection.Top
ActiveSheet.Labels.Add(L1, T1, L2 - L1, T2 - T1).Select
With Selection
.Name = "Your Label"
.Placement = xlMoveAndSize
.Characters.Text = ""
.OnAction = "test2"
End With
Range("A1").Select
ActiveCell = "Click on Cell A3"
End If
End Sub
Sub test2()
If Range("A3") = "" Then
Range("A3") = "X"
Else
Range("A3") = ""
retVal = MsgBox("Do you want to delete the label control ?", vbYesNo + vbQuestion)
If retVal = vbYes Then
ActiveSheet.Shapes("Your Label").Delete
Range("A1") = ""
End If
End If
End Sub
Last edited by MJBNET; Mar 26th, 2005 at 10:59 AM.
Reason: typo in remark - C3 should be A3.
-
Mar 26th, 2005, 01:46 AM
#4
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|