Fonction .find sur un range variable

Kran

XLDnaute Nouveau
Bonjour à tous,

J'ai un petit souci :

Code:
Set wbcs = Workbooks(ActiveWorkbook.Name).Sheets(ActiveSheet.Name)

                With wbcs.Range(Cells(num + 1, 1), Cells(100, 1))
                    Set foundrange = .Find(What:="LINING*", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
                        xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
                        True, SearchFormat:=False) 'lining 2
                    If Not foundrange Is Nothing Then
                        num = foundrange.Row
                        awb.Cells(a, 26) = wbcs.Cells(num + 2, 4)
                        awb.Cells(a, 27) = wbcs.Cells(num, 10)
                        awb.Cells(a, 29) = wbcs.Cells(num, 2)
                    End If
                End With

me renvoie une erreur 1004 sur
Code:
with wbcs.Range(Cells(num + 1, 1), Cells(100, 1))

Alors que la fonction find fonctionne très bien sur page entière :

Code:
Set wbcs = Workbooks(ActiveWorkbook.Name).Sheets(ActiveSheet.Name)

            Set foundrange = wbcs.Cells.Find(What:="LINING*", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
                xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
                True, SearchFormat:=False) 'lining 1
            If Not foundrange Is Nothing Then
                num = foundrange.Row
                awb.Cells(a, 26) = wbcs.Cells(num + 2, 4)
                awb.Cells(a, 27) = wbcs.Cells(num, 10)
                awb.Cells(a, 29) = wbcs.Cells(num, 2)
            End If

Un petit coup de main? d'avance merci
 

Kran

XLDnaute Nouveau
Re : Fonction .find sur un range variable

cOOl, ça a l'air de marcher,

mais du coup il me renvoie une erreur 13 sur le bloc find :

Code:
Set foundrange = .Find(What:="LINING*", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
               xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
               True, SearchFormat:=False) 'lining 2

Pour explication, je cherche dans un fichier la première ligne contenant Lining, et s'il la trouve qu'il en cherche une deuxième.
Voici le bloc dans ça totalité
Code:
            Set wbcs = Workbooks(ActiveWorkbook.Name).Sheets(Sheets(b).Name)

            Set foundrange = wbcs.Cells.Find(What:="LINING*", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
                xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
                True, SearchFormat:=False) 'lining 1
            If Not foundrange Is Nothing Then
                num = foundrange.Row
                awb.Cells(a, 26) = wbcs.Cells(num + 2, 4)
                awb.Cells(a, 27) = wbcs.Cells(num, 10)
                awb.Cells(a, 29) = wbcs.Cells(num, 2)
                
                With wbcs.Range(wbcs.Cells(num + 1, 1), wbcs.Cells(100, 1))
                    Set foundrange = .Find(What:="LINING*", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
                        xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
                        True, SearchFormat:=False) 'lining 2
                    If Not foundrange Is Nothing Then
                        num = foundrange.Row
                        awb.Cells(a, 26) = wbcs.Cells(num + 2, 4)
                        awb.Cells(a, 27) = wbcs.Cells(num, 10)
                        awb.Cells(a, 29) = wbcs.Cells(num, 2)
                    End If
                End With
            End If
 

Robert

XLDnaute Barbatruc
Repose en paix
Re : Fonction .find sur un range variable

Bonjour Kran, bonjour le forum,

Je pense que le problème vient de After:=ActiveCell car si la cellule active ne fait pas partie de la plage de recherche ça bugge...
Peut-ête en remplaçant par :
Code:
After:=wbcs.Cells(num + 1, 1)
 

Discussions similaires

Statistiques des forums

Discussions
312 470
Messages
2 088 699
Membres
103 927
dernier inscrit
Mkeal