Cell selection toggle effect.

Herakles

Well-known Member
Joined
Jul 5, 2020
Messages
927
Office Version
  1. 365
Platform
  1. Windows
I'm developing a booking system where a cell value represents no booking or a booking and its value and colour is set as appropriate.

These cells are arranged in a grid with people represented in rows and times of the day represented in columns.

I'd like to be able use the selection of a cell as a toggle.

In the Worksheet_SelectionChange event I register and process the selection of a cell (book or unbook) and then select
another cell in an obsolete area of the worksheet.

This enables me to select the cell again to reverse the booking.

It works fine but there may be a better way.

I've used Application.ScreenUpdating to try and suppress screen flickering but it does not work.
It is the screen flickering that I'd like to avoid.

Does anybody have any ideas as to how I can accomplish this toggle effect in a cell?

Thanks
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
You might find that double-clicking is a better interface. If you put this the the sheet's code module, double clicking a cell in B2:G10 will toggle that cell between booked and unbooked.

VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Not Application.Intersect(Target, Range("B2:G10")) Is Nothing Then
        Cancel = True
        If Target.Value = "Booked" Then
            Target.Value = "unbooked"
        Else
            Target.Value = "Booked"
        End If
    End If
End Sub
 
Upvote 0
You might find that double-clicking is a better interface. If you put this the the sheet's code module, double clicking a cell in B2:G10 will toggle that cell between booked and unbooked.

VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Not Application.Intersect(Target, Range("B2:G10")) Is Nothing Then
        Cancel = True
        If Target.Value = "Booked" Then
            Target.Value = "unbooked"
        Else
            Target.Value = "Booked"
        End If
    End If
End Sub
Thanks Mike

I've not used Worksheet_BeforeDoubleClick before and it looks like it is the way forward.

Much appreciated considering that Davis CA Local Time is 02:03.
 
Upvote 0
You might find that double-clicking is a better interface. If you put this the the sheet's code module, double clicking a cell in B2:G10 will toggle that cell between booked and unbooked.

VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Not Application.Intersect(Target, Range("B2:G10")) Is Nothing Then
        Cancel = True
        If Target.Value = "Booked" Then
            Target.Value = "unbooked"
        Else
            Target.Value = "Booked"
        End If
    End If
End Sub

Works a treat Mike.

I'm booking volunteers in to help at vaccination centres.
 
Upvote 0

Forum statistics

Threads
1,214,632
Messages
6,120,649
Members
448,975
Latest member
sweeberry

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top