Search code examples
vbaexcelcompilationbasic

Compile error saying "wrong number of arguments or invalid property assignment"


I have code that populates cells when double clicked on the cell. Here it is:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)  
    If Not Intersect(Target, Range("C10:C19", "D10:D19", "E10:E19")) Is Nothing Then  
        Cancel = True  
        Target.Formula = Date  
    End If  
End Sub  

The code was working fine until I added "E10:E19" then it gives me a compile error saying wrong number of arguments or invalid property assignments and then it highlights the first line of code Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

Full disclosure: I am a total noob at this so any fixes or advice please explain like I am 5 years old.


Solution

  • Try this

    Option Explicit
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
        If Not Intersect(Target, [C10:C19, D10:D19, E10:E19]) Is Nothing Then
            Cancel = True
            Target.Formula = Date
        End If
    End Sub
    

    "C10:C19", "D10:D19", "E10:E19" Range should be one string not multiple strings
    Examnple "C10:C19, D10:D19, E10:E19"