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.
Printable View
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.
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)
Target.Value = "X"
End Sub
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
open a workbook, put this code in a module, run as macro "test1"...should do just what you want...Quote:
Originally Posted by Latoya
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
try to log-on www.vbrad.com many sample there :thumb: