Double click function not perform

Vincent88

Active Member
Joined
Mar 5, 2021
Messages
382
Office Version
  1. 2019
Platform
  1. Windows
  2. Mobile
Hi Guys,
My code is to copy a cell value to its four adjacent cells. I have already encoded to paste cells except those patterned and non empty cells but it does not copy the value to the weekend cells with color RGB(255,245,230. Please advise where goes wrong ?

TestDropDownList_3.xlsm
ABHIJKLMNOPQR
1MDateAttendance1-Feb2-Feb3-Feb4-Feb5-Feb6-Feb7-Feb8-Feb9-Feb10-Feb11-Feb
2DateSummary1234567891011
3Larry QT:16 L:0.5 D:2.5 E:0 N:0DD
4Mandy HT:16 L:0.5 D:3.5 E:0 N:0KDK
5John GT:16 L:0 D:1 E:2 N:0
202202
Cells with Data Validation
CellAllowCriteria
A2List=Data!$P$2:$P14
A3List=Data!$P$2:$P$14
A4List=Data!$P$2:$P$13
A5:A6List=Data!$P$2:$P$12




VBA Code:
Private Sub Workbook_SheetBeforeDoubleClick(ByVal sh As Object, ByVal Target As Range, Cancel As Boolean)
    If sh.Name = "Data" Then Exit Sub
  
    Application.ScreenUpdating = False
     
On Error Resume Next

Dim lrow As Long
Dim Lcol As Long
Dim rngArea As Range
Dim wkend As Boolean
Dim pat As Double

lrow = Range("A" & Rows.Count).End(xlUp).Row
Lcol = Cells(1, Columns.Count).End(xlToLeft).Column

Set rngArea = Range(Cells(3, 8), Cells(lrow, Lcol))

Debug.Print rngArea.Address

If Not Intersect(Target, rngArea) Is Nothing Then
    Cancel = True
    If Not IsEmpty(Target.Value) Then                       
      'Target.Offset(, 1).Resize(, 4).Value = Target.Value
      For col4 = 1 To 4
           Dim adjcell As Range
           Set adjcell = Target.Offset(, col4)
           adjcellpat = Target.Offset(, col4).Interior.Pattern
           adjcellcol = Target.Offset(, col4).Interior.Color
           If adjcellpat <> -4142 Then                                                                        'Cells with any pattern
                        'No value to be pasted 
              ElseIf Target.Offset(, col4).Interior.Color = RGB(255, 245, 230) Then       'Color in weekend column
                       Target.Offset(, col4).Value = Target.Value
                                      
                ElseIf adjcell.Interior.Color = 16777215 And adjcell.Value = "" And adjcell.Interior.Pattern = xlNone Then                'Other blank cells, no pattern and no color
                       Target.Offset(, col4).Value = Target.Value      'Workable
                    
              
           Else
           End If
      Next col4
    
    
    
    
    Else
'ON/OFF FORMATTING CELLS TO PATTERN
'https://www.mrexcel.com/board/threads/error-before-double-click-function.1185307/#post-5774690
'Post 4 Joe4
  
  
'   Get interior pattern number
    pat = Target.Interior.Pattern
  
'   Check to see if weekend
    wkend = IsWeekend(Cells(1, Target.Column))
  
    '   Check to see if it has no lined pattern at all
        'pattern -4142 = xlPatternNone  and pattern 1 = xlPatternSolid
        If (pat = -4142) Or (pat = 1) Then
            Target.Interior.Pattern = xlPatternUp               ' or xlPatternLightVertical
            Target.Interior.PatternColor = RGB(166, 166, 166)
        Else
  
    '       Check to see if it has lined pattern
            'If pat = -4162 Then               'Pattern -4162 = xlPatternUp only
            If Not IsEmpty(pat) Then           'Applicable to any pattern
    '           Check to see if weekend
                If wkend = True Then
                    Target.Interior.Pattern = xlNone
                    Target.Interior.Color = RGB(255, 245, 230)
                Else
                    Target.Interior.Pattern = xlNone
                End If
            End If
        End If
    End If
End If
 

Attachments

  • copyerror4cells.png
    copyerror4cells.png
    54.1 KB · Views: 19

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
I always like it when posters tell me in specific details what there trying to achieve
Rather then provide very few details and then show me a long script that does not work for them.
Would you please explain with specific details what your wanting to do and let me write the code the way I like to do it. Thanks
 
Upvote 0
Hi, What I would like is to copy the target cell value to the next 4 adjacent cells. If those adjacent cells are patterned, colored and non empty then skip it but the weekend cells in color RG(255, 245, 230) should also be pasted the value if it is empty and non patterned.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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