Insertion de ligne erreur 1004 : la méthode insert de la classe range a echoué

Fermé
INSAStudent - 12 nov. 2021 à 17:18
yg_be Messages postés 22697 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 18 avril 2024 - 12 nov. 2021 à 19:28
Bonsoir,

Je n'arrive pas à résoudre ce problème. Des que je clique sur le bouton depuis mon onglet "BD Tickets" j'ai l'erreur 1004 qui survient. Voilà mon code si qq'un peut m'aider :

Sub Archiver_Tickets_Advanced()

'Déclaration des variables
Dim wb As Workbook
Dim wsd As Worksheet
Dim wsb As Worksheet
Dim i As Integer
Dim j As Integer
Dim nbre As Long
Dim existing_codes() As Variant 'Variant = forme de variable la plus générale possible, prend en compte string, nombre, tableua, matrice
Dim new_codes() As Variant

Set wb = Application.ThisWorkbook
Set wsd = wb.Worksheets("BD Tickets")
Set wsb = wb.Worksheets("MEP Advanced")

'Dimensionner la matrice existing_codes
ReDim existing_codes(1 To wsd.Cells(wsd.Rows.Count, 5).End(xlUp).Row - 1 + 6, 1 To 1)

For nbre = 7 To UBound(existing_codes())
existing_codes(nbre, 1) = Range("code_tck").Cells(nbre + 1 - 6, 1).Value
Next nbre

'Dimensionner la matrice new_codes
ReDim new_codes(1 To 6, 1 To 1)

For i = 1 To 6
generate:
new_codes(i, 1) = "BEP" & WorksheetFunction.RandBetween(100000, 999999)
For j = 1 To UBound(existing_codes())
If new_codes(i, 1) = existing_codes(j, 1) Then
GoTo generate
End If
Next j
existing_codes(i, 1) = new_codes(i, 1)
wsd.Rows(2).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("code_tck").Cells(2, 1).Value = new_codes(i, 1)

Next i
A voir également:

1 réponse

yg_be Messages postés 22697 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 18 avril 2024 1 471
12 nov. 2021 à 19:28
bonjour,
peux-tu partager ton fichier?
0