ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Toggle Button (https://www.excelbanter.com/excel-programming/414890-toggle-button.html)

ranswrt

Toggle Button
 
I have 5 togglebutton controls on a worksheet. When they are toggled on a
range of cells are highlighted and unlocked. When they are toggled off the
range of cell are unhighlited and locked is turned on. The problem I have is
the toggle button can be toggled off before the enter key has been pressed
when making changes to the cell. Is there a way to disable the toggle button
when data is started to be typed into a cell until the enter key is pressed
or another cell is selected?
Thanks

[email protected]

Toggle Button
 
On Jul 30, 5:31*pm, ranswrt wrote:
I have 5 togglebutton controls on a worksheet. *When they are toggled on a
range of cells are highlighted and unlocked. *When they are toggled off the
range of cell are unhighlited and locked is turned on. *The problem I have is
the toggle button can be toggled off before the enter key has been pressed
when making changes to the cell. *Is there a way to disable the toggle button
when data is started to be typed into a cell until the enter key is pressed
or another cell is selected?
Thanks


Right click the sheet you are working in and go to view code... enter
the following...

'=================================================
' The code below will invoke a macro to run when someone clicks a cell
so in this case you can have it disable that toggle button...
'=================================================
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
ToggleButton1.Enabled = False
End Sub

'=================================================
' The code below will invoke a macro after someone finished entering
data into a cell...
'=================================================
Private Sub Worksheet_Calculate()
ToggleButton1.Enabled = True
End Sub


'---------------------------------------- You could also try this
below for a similar effect (not sure what)
Private Sub Worksheet_Change(ByVal Target As Range)

End Sub

ranswrt

Toggle Button
 
That works except for when there is only cell unlocked on the sheet. Any
ideas on how to get around that?

" wrote:

On Jul 30, 5:31 pm, ranswrt wrote:
I have 5 togglebutton controls on a worksheet. When they are toggled on a
range of cells are highlighted and unlocked. When they are toggled off the
range of cell are unhighlited and locked is turned on. The problem I have is
the toggle button can be toggled off before the enter key has been pressed
when making changes to the cell. Is there a way to disable the toggle button
when data is started to be typed into a cell until the enter key is pressed
or another cell is selected?
Thanks


Right click the sheet you are working in and go to view code... enter
the following...

'=================================================
' The code below will invoke a macro to run when someone clicks a cell
so in this case you can have it disable that toggle button...
'=================================================
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
ToggleButton1.Enabled = False
End Sub

'=================================================
' The code below will invoke a macro after someone finished entering
data into a cell...
'=================================================
Private Sub Worksheet_Calculate()
ToggleButton1.Enabled = True
End Sub


'---------------------------------------- You could also try this
below for a similar effect (not sure what)
Private Sub Worksheet_Change(ByVal Target As Range)

End Sub



All times are GMT +1. The time now is 07:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com