Double Click function on/off

Vincent88

Active Member
Joined
Mar 5, 2021
Messages
382
Office Version
  1. 2019
Platform
  1. Windows
  2. Mobile
Hi Guys,
How to change my code to enable or disable the formatting cell ( to make it patterned if it isn't or return to non-patterned if it is patterned).

VBA Code:
Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
If Sh.Name = "Data" Then Exit Sub

Dim lr As Long
Dim Lc As Long
lr = Range("A" & Rows.Count).End(xlUp).Row
Lc = Cells(1, Columns.Count).End(xlToLeft).Column
Dim rngArea As Range
Set rngArea = Range(Cells(3, 8), Cells(lr, Lc))

Debug.Print rngArea.Address

If Not Intersect(Target, rngArea) Is Nothing Then
   Cancel = True
   If Not IsEmpty(Target.Value) Then Exit Sub
        
        With Target.Interior
          .Pattern = xlPatternUp
          .PatternColor = RGB(166, 166, 166)
        End With
    
End If
End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
You could try something like
VBA Code:
        With Target.Interior
            If .Pattern = xlPatternUp Then
                .Pattern = xlNone
            Else
                .Pattern = xlPatternUp
                .PatternColor = RGB(166, 166, 166)
            End If
        End With
 
Upvote 0
Solution

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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