Appliquer VBA sur d autres classeurs

Staple1600

XLDnaute Barbatruc
Re

@belk-zak
Il suffit de copier le code VBA dans le module de la feuille idoine, non ?
(et d'adapter selon les besoins: le nom de la feuille, la plage des cellules etc...)
NB: Sans oublier d'insérer un ComboBox nommé ComboBox1
Rien de bien compliqué, si tu es l'auteur du code VBA ci-dessous, non ?
VB:
Dim a(), mémo, f
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  Set f = Sheets("sheet1")
  Set zSaisie = Range("E2:E500")
  If Not Intersect(zSaisie, Target) Is Nothing And Target.Count = 1 Then
    If mémo <> "" Then If IsError(Application.Match(Range(mémo), a, 0)) Then Range(mémo) = ""
    a = Application.Transpose(f.Range("B2:B" & f.[c65000].End(xlUp).Row))
    Me.ComboBox1.List = a
    Me.ComboBox1.Height = Target.Height + 3
    Me.ComboBox1.Width = Target.Width
    Me.ComboBox1.Top = Target.Top
    Me.ComboBox1.Left = Target.Left
    Me.ComboBox1 = Target
    Me.ComboBox1.Visible = True
    Me.ComboBox1.Activate
    mémo = Target.Address
  Else
    Me.ComboBox1.Visible = False
  End If
End Sub
Private Sub ComboBox1_Change()
  If Me.ComboBox1 <> "" And IsError(Application.Match(Me.ComboBox1, a, 0)) Then
    Set d1 = CreateObject("Scripting.Dictionary")
    tmp = UCase(Me.ComboBox1) & "*"
    For Each c In a
      If UCase(c) Like tmp Then d1(c) = ""
    Next c
    Me.ComboBox1.List = d1.keys
    Me.ComboBox1.DropDown
  End If
  ActiveCell.Value = Me.ComboBox1
End Sub
Private Sub ComboBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
  ComboBox1.List = Application.Transpose(f.Range("b2:b" & f.[b65000].End(xlUp).Row))
  Me.ComboBox1.DropDown
End Sub
Private Sub ComboBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
  If KeyCode = 13 Then
    If IsError(Application.Match(ActiveCell, a, 0)) Then ActiveCell = ""
    ActiveCell.Offset(1).Select
  End If
End Sub
NB: Après relecture, on dirait bien un code de JB, non ?
Dans ce cas, attends qu'il passe dans ton fil ;)
 
Dernière édition:

belk-zak

XLDnaute Nouveau
Pas du-tout c'est pourquoi je suis venu vous demander de l'aide mais en l'occurrence j'essaie d'apprendre et comprendre VBA sur internet et j'avoue que c'est très intéressant et je commence à comprendre la signification des codes petit à petit, sauf que je suis pressé par le fichier, mais bon merci comme même...
 

Discussions similaires

Réponses
2
Affichages
426

Statistiques des forums

Discussions
311 725
Messages
2 081 941
Membres
101 847
dernier inscrit
Djigbenou