Fonction recherche sur Userforum / Sheet Variable

  • Initiateur de la discussion Fab61
  • Date de début
F

Fab61

Guest
Bonjour,

J'ai un userform avec une fonction recherche qui marche trés bien, cepedant j'ai ajouter une feuille et suivant la feuille en cours ma fonction recherche avec le bonton 'OK' doi s'apater a celle ci et je n'arrive pas a mettre la feuille en cours en tant que variable

voici mon code pour la feuille :

Code:
Private Sub cmd_choix_refOK_Click()
On Error GoTo ErrHandler
Dim CurrentRow As Range


  If Sheets('[color=#FF0000]LAFEUILLEENCOURS[/color]').Select = True Then
      [color=#FF0000]LAFEUILLEENCOURS[/color].Range('B1').Select
  MyFirstAddress = ''
  If cxbreferencefiltre.Text = '' Then Exit Sub
  Set MyCell = Cells.Find(What:=cxbreferencefiltre.Text, After:=[color=#FF0000]LAFEUILLEENCOURS[/color].Range('b1'), LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False)
   Exit Sub
  End If
  
  If Not (MyCell Is Nothing) Then
    MyCell.Select
    MyFirstAddress = MyCell.Address
    Set CurrentRow = Selection.EntireRow
  Else
    MsgBox 'Aucune Fiche ne correspond...', vbExclamation
  End If
  Exit Sub
End Sub

Donc en gros c de lui dure que si on est sur la sheet1 donc rechercher sur celle ci si on est sur la sheet2 rechercher sur celle ci ...

Merci
Fabien
 
F

Fab61

Guest
Oupss les couelurs rouge dans le code c pas genial

voici le code sans l'erreur :

Code:
Private Sub cmd_choix_refOK_Click()
On Error GoTo ErrHandler
Dim CurrentRow As Range


  If Sheets('LAFEUILLEENCOURS').Select = True Then
      LAFEUILLEENCOURS.Range('B1').Select
  MyFirstAddress = ''
  If cxbreferencefiltre.Text = '' Then Exit Sub
  Set MyCell = Cells.Find(What:=cxbreferencefiltre.Text, After:=LAFEUILLEENCOURS.Range('b1'), LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False)
   Exit Sub
  End If
  
  If Not (MyCell Is Nothing) Then
    MyCell.Select
    MyFirstAddress = MyCell.Address
    Set CurrentRow = Selection.EntireRow
  Else
    MsgBox 'Aucune Fiche ne correspond...', vbExclamation
  End If
  Exit Sub
End Sub
 

PascalXLD

XLDnaute Barbatruc
Modérateur
Re:Fonction recherche sur Userforum / Sheet Variab

Bonjour

Bon sans rentrer dans les détails du code il suffit peut-être de juste remplacer

If Sheets('LAFEUILLEENCOURS').Select = True Then

LAFEUILLEENCOURS.Range('B1').Select

Par

activesheet.range('B1').select
 

Discussions similaires

Statistiques des forums

Discussions
312 595
Messages
2 090 093
Membres
104 374
dernier inscrit
cheick.coulibaly@dcsmali.