sonicdemonic
05-30-2008, 09:50 AM
Current I have some script which alters a cell OnSelectionChange. Is there anyway to catch the user clicking on the currently selected? Meaning, a cell is currently selected, but the use clicks on it again.
What I am trying to accomplish.
These cells are marked with an X. I am trying to simulate single click functionality. If you click on a cell and there is no X, it puts one. If you click on a cell and there is a X, it removes it. What I have works great except when you click on a cell and it adds the X, you have to change the selected cell to get the script to remove the X. By doing that you added another X to a different cell.
Thanks
sonicdemonic
05-30-2008, 10:01 AM
Is there a way to set range.select to nothing?
I think I have a pretty good workaround:
Put hyperlinks (Insert->Hyperlink) into the each of the cells that should have this functionality. Set the reference to the cell itself and the text to X. Whenever a cell is clicked, you get the _FollowHyperlink worksheet event. In the handler, toggle the text colour between white and black (or between the background colour and automatic, if you're using background colours) to make the X's appear and disappear.
The mouse icon will change from standard to link over these cells, but I don't see any problem with that. If you don't like it, there's probably a way to customize that as well, though.
sonicdemonic
05-30-2008, 10:29 AM
Well, your solution would work. I have alot of cells tho .. since i have figure out this way.
ElseIf targetColumn = "N" Then
If Target.Text = "" Then
ActiveCell.Formula = "X"
CellSelect = True
Range("L" & Target.Row).Select
ActiveCell.FormulaR1C1 = ""
Range("M" & Target.Row).Select
ActiveCell.FormulaR1C1 = ""
Range("M" & Target.Row).Select
CellSelect = False
ElseIf Target.Text = "X" Then
ActiveCell.Formula = ""
CellSelect = True
Range("M" & Target.Row).Select
CellSelect = False
End If
End If
The cells are in 3 columns across. So i just edited my current code to select a cell next to the one selected. I previously used a public variable to store whether the code was selecting cells to bypass the code OnSelection.
Thanks.
I have alot of cells tho
*shrug* You can easily use a macro to create the hyperlinks.
But if your way works, all the better! :)
Colin Legg
05-30-2008, 10:56 AM
Well, your solution would work. I have alot of cells tho .. since i have figure out this way.
The cells are in 3 columns across. So i just edited my current code to select a cell next to the one selected. I previously used a public variable to store whether the code was selecting cells to bypass the code OnSelection.
Thanks.
So if I read this correctly you are now trapping the worksheet's selection_change event and selecting another cell within that event?
Don't you end up in an infinite loop?
You might need to toggle the application object's enable events property off and on....