Error 1004: Method 'Range' of object '_Worksheet' failed

Solved
Inconnu404 Posted messages 24 Registration date   Status Member Last intervention   -  
Inconnu404 Posted messages 24 Registration date   Status Member Last intervention   -
Hello everyone,

I'm reaching out because I've been stuck on this problem for a day.

When I run the macro, I hit the error mentioned in the title on line 24.
 Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) If Not Application.Intersect(Target, Range("G:G")) Is Nothing Then Dim Path As String, File As String, Extraction As String, Summary As String Dim projWorkbook As Workbook, destinationWorkbook As Workbook If Target.Value = "" Then Exit Sub Path = Range("b" & Target.Row) File = Range("c" & Target.Row) Extraction = Range("d" & Target.Row) Summary = Range("a" & Target.Row) Set projWorkbook = Application.Workbooks.Open(Path & File, , True) 'Opening the file Set destinationWorkbook = ThisWorkbook With Worksheets("Materials") If .FilterMode = True Then .ShowAllData 'Removing existing filters End With projWorkbook.Sheets("Materials").Cells.Copy destinationWorkbook.Sheets(Extraction).Range("A1") 'Extracting information into its specific sheet projWorkbook.Close False 'Removing duplicates without losing information Worksheets("Summary 2020").Select Set D1 = CreateObject("Scripting.Dictionary") Set F1 = Sheets(Extraction) Set F2 = Sheets(Summary) Range(F2.Range("A3"), F2.Range("AA6000")).ClearContents 'place of the error With F2 If .FilterMode = True Then .ShowAllData End With F2.Columns("AA").NumberFormat = "0" ncol = F1.[a4].CurrentRegion.Columns.Count + 27 nlig = F1.[a4].CurrentRegion.Rows.Count + 4 D1.CompareMode = vbTextCompare For line = 1 To nlig key = sansAccent(F1.Cells(line, "H")) & sansAccent(F1.Cells(line, "J")) ' name+first name D1(key) = "" ligT = Application.Match(key, D1.keys, 0) For col = 1 To ncol If col = 3 Or col = 4 Then If F1.Cells(line, col) <> "" Then F2.Cells(ligT, col) = F1.Cells(line, col).Text Else If F1.Cells(line, col) <> "" Then If F2.Cells(ligT, col) <> "" Then If InStr(F2.Cells(ligT, col), F1.Cells(line, col)) = 0 Then F2.Cells(ligT, col) = F2.Cells(ligT, col) & Chr(10) & F1.Cells(line, col).Text End If Else F2.Cells(ligT, col) = F1.Cells(line, col).Text End If End If End If Next col Next line End If End Sub


I want to clarify several points:
- The first part (opening and extraction) works perfectly (see the post "Insertion of choice window in a macro")
- The second part (Removing duplicates) works fine when the error does not block the macro. So no improvement proposals please.
- The information on lines 22 and 23 (
Extraction
and
Summary
) corresponds exactly to the requested search.
- Line 19 has no impact on the second part.
- Since the macro is linked to confidential files, I cannot put my macro online.

Can someone help me?

Thanks in advance.

--
2 brains are better than 1.

3 answers

M-12 Posted messages 1349 Status Member 285
 
Re,
Remplace tes "Extraction As Worksheet, Résumé As Worksheet"
en "As Worksheet"
1
Inconnu404 Posted messages 24 Registration date   Status Member Last intervention  
 
It doesn't work because they are used at the beginning in lines 8 and 9, and also linked to my initial selection.
0
M-12 Posted messages 1349 Status Member 285
 
Hello
Test by changing line 24
Range(F2.Range("A3"), F2.Range("AA6000")).ClearContents


to

F2.Range(Cells(3,"A"),cells(6000,"AA")).ClearContents 
0
Inconnu404 Posted messages 24 Registration date   Status Member Last intervention  
 
Hello,

I already tried but I'm still stuck.

I tried again just in case, but it didn't make any difference.
0
cs_Le Pivert Posted messages 8437 Status Contributor 730
 
Hello,

like this:

F2.Range("A3:AA6000").ClearContents 


0
Inconnu404 Posted messages 24 Registration date   Status Member Last intervention  
 
Hello,

Indeed, it's the solution.
I don't know why I wrote it that way when it's the same sheet.

Thanks again, cs_Le Pivert
0