erreur 1004

jad73

XLDnaute Occasionnel
bonjour le forum
j'ai une erreur 1004,comme je n'y connais pas grand chose j'ai mis le code ci-dessous,l'erreur ce trouve a cette ligne:
"With .Resize(UBound(oCpt, 1), UBound(oCpt, 2))"
si quelqu'un peut m'aider.
merci


Sub ecart()

Dim pDat As Object, oCel As Range
Dim oVar As New Collection
Dim oCpt, i As Long, j As Long, k As Long, n As Long, tf As Boolean
Set pDat = Range("DATA") 'Plage contenant les données.(B2:U600)
With Range("SORT") 'Première cellule de résultat. (W2)
.CurrentRegion.Offset(1, 0).ClearContents
Application.ScreenUpdating = False
On Error Resume Next
For Each oCel In pDat.Cells
oVar.Add oCel.Value, CStr(oCel.Value)
Next oCel
On Error GoTo 0
ReDim oCpt(1 To oVar.Count, 1 To 2) As Variant
For i = 1 To oVar.Count
oCpt(i, 1) = oVar(i)
n = 0
For j = 1 To pDat.Rows.Count
tf = False
For k = 1 To pDat.Columns.Count
If pDat.Cells(j, k).Value = oVar(i) Then
tf = True
n = n + 1
Exit For
End If
Next k
If Not tf Or j = pDat.Rows.Count Then
If n > 1 Then
If n > UBound(oCpt, 2) Then ReDim Preserve oCpt(1 To oVar.Count, 1 To n)
oCpt(i, n) = oCpt(i, n) + 1
End If
tf = False
n = 0
End If
Next j
Next i
Set oVar = Nothing
With .Resize(UBound(oCpt, 1), UBound(oCpt, 2))'l'erreur est a cette ligne
.Value = oCpt
.Sort Key1:=Range("SORT"), Order1:=xlAscending, Header:=xlNo, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
End With
Application.ScreenUpdating = True
End With
End Sub
 

ROGER2327

XLDnaute Barbatruc
Re : erreur 1004

Bonjour jad73
Ce code fonctionne dans l'environnement pour lequel je l'ai écrit (je viens de le vérifier). Si vous voulez de l'aide, déposez le classeur dans lequel vous voulez l'utiliser : on trouvera peut-être une solution.​
ROGER2327
#4859


Samedi 14 Décervelage 138 (Saints 4 Sans-Cou, enchanteurs, SQ)
22 Nivôse An CCXIX
2011-W02-2T02:41:44Z
 

Discussions similaires

Réponses
11
Affichages
346

Statistiques des forums

Discussions
312 451
Messages
2 088 519
Membres
103 876
dernier inscrit
Audrey82