Perform action when cell is clicked

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!
 
C

Chip Pearson

Jason,

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

Chip Pearson

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
 
H

Harald Staff

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top