Perform action when cell is clicked

  • Thread starter Thread starter Jason
  • Start date Start date
J

Jason

I need help,
I am trying to write a module that will change the value
of a cell when a different one is selected.

For example - user clicks on B1 (only selecting the cell -
no change of value) and C1 value would then show "Y" - if
B1 were clicked again then C1 would change to "".

I can figure everything out except how to make excel/VBA
recognize that a cell has been clicked.

Thanks for any advice!
 
Jason,

Put the following code in the sheet code module for the appropriate
worksheet.
 
Jason,

Put the following code in the sheet code module for the appropriate
worksheet.


Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Target.Address = "$B$1" Then
Application.EnableEvents = False
If Range("C1") = "Y" Then
Range("C1") = ""
Else
Range("C1") = "Y"
End If
Application.EnableEvents = True
End If
End Sub
 
Hi

Rightclick the sheet tab, choose "View code". Paste this into the module
that appear:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$B$1" Then
If Cells(1, 3).Value = "Y" Then
Cells(1, 3).Value = "N"
Else
Cells(1, 3).Value = "Y"
End If
End If
End Sub
 
Back
Top