Bonjour,
je réalise un stage en allemagne et je dois mettre en place un programme mais
Je suis un débutant sur VBA
j´aimerai réaliser une macro permettant de rechercher un texte sur une colonne mai sans besoin de taper entièrement le texte
ex : recherche soleil brille
si on tape so il faudrait afficher tous les mots commencant par so
Cette action est irreversible, confirmez la suppression du commentaire ?
Signaler le commentaire
Veuillez sélectionner un problème
Nudité
Violence
Harcèlement
Fraude
Vente illégale
Discours haineux
Terrorisme
Autre
Francois L
jager57 a écrit :
Bonjour, je réalise un stage en allemagne et je dois mettre en place un programme mais Je suis un débutant sur VBA j´aimerai réaliser une macro permettant de rechercher un texte sur une colonne mai sans besoin de taper entièrement le texte ex : recherche soleil brille si on tape so il faudrait afficher tous les mots commencant par so
quelqu´un peu m´aider SVP merci
Bonjour,
Première piste, aller voir dans l'aide de VBA ce qui est dit sur l'opérateur Like.
Pour le reste, il faudrait préciser un peu...
-- François L
jager57 a écrit :
Bonjour,
je réalise un stage en allemagne et je dois mettre en place un programme mais
Je suis un débutant sur VBA
j´aimerai réaliser une macro permettant de rechercher un texte sur une colonne
mai sans besoin de taper entièrement le texte
ex : recherche soleil brille
si on tape so il faudrait afficher tous les mots commencant par so
quelqu´un peu m´aider SVP
merci
Bonjour,
Première piste, aller voir dans l'aide de VBA ce qui est dit sur
l'opérateur Like.
Bonjour, je réalise un stage en allemagne et je dois mettre en place un programme mais Je suis un débutant sur VBA j´aimerai réaliser une macro permettant de rechercher un texte sur une colonne mai sans besoin de taper entièrement le texte ex : recherche soleil brille si on tape so il faudrait afficher tous les mots commencant par so
quelqu´un peu m´aider SVP merci
Bonjour,
Première piste, aller voir dans l'aide de VBA ce qui est dit sur l'opérateur Like.
Pour le reste, il faudrait préciser un peu...
-- François L
CAP2
Salut,
comme le dit François, ton besoin n'est pas très clair.
Si l'on part du principe que ton souhait est de taper une chaine et qu'excel affiche les contenus commençant par la chaine saisie, on peut faire une macro de filtre. Dans mon exemple, j'ai pris un tableau de 4 colonnes (de A à D), et j'ai pris pour exemple le cas où la recherche porterait sur le deuxième champ (adapte à ton cas):
Sub Filtre() Dim chaine As String
chaine = InputBox("Garder les noms commençant par :")
Bonjour, je réalise un stage en allemagne et je dois mettre en place un programme mais Je suis un débutant sur VBA j´aimerai réaliser une macro permettant de rechercher un texte sur une colonne mai sans besoin de taper entièrement le texte ex : recherche soleil brille si on tape so il faudrait afficher tous les mots commencant par so
quelqu´un peu m´aider SVP merci
Salut,
comme le dit François, ton besoin n'est pas très clair.
Si l'on part du principe que ton souhait est de taper une chaine et qu'excel
affiche les contenus commençant par la chaine saisie, on peut faire une
macro de filtre. Dans mon exemple, j'ai pris un tableau de 4 colonnes (de A
à D), et j'ai pris pour exemple le cas où la recherche porterait sur le
deuxième champ (adapte à ton cas):
Sub Filtre()
Dim chaine As String
chaine = InputBox("Garder les noms commençant par :")
"jager57" <nospam_christophe.jager1@9online.fr> a écrit dans le message de
news: nuGdnZ4zafmd0DTV4p2dnAA@giganews.com...
Bonjour,
je réalise un stage en allemagne et je dois mettre en place un programme
mais
Je suis un débutant sur VBA
j´aimerai réaliser une macro permettant de rechercher un texte sur une
colonne
mai sans besoin de taper entièrement le texte
ex : recherche soleil brille
si on tape so il faudrait afficher tous les mots commencant par so
comme le dit François, ton besoin n'est pas très clair.
Si l'on part du principe que ton souhait est de taper une chaine et qu'excel affiche les contenus commençant par la chaine saisie, on peut faire une macro de filtre. Dans mon exemple, j'ai pris un tableau de 4 colonnes (de A à D), et j'ai pris pour exemple le cas où la recherche porterait sur le deuxième champ (adapte à ton cas):
Sub Filtre() Dim chaine As String
chaine = InputBox("Garder les noms commençant par :")
Bonjour, je réalise un stage en allemagne et je dois mettre en place un programme mais Je suis un débutant sur VBA j´aimerai réaliser une macro permettant de rechercher un texte sur une colonne mai sans besoin de taper entièrement le texte ex : recherche soleil brille si on tape so il faudrait afficher tous les mots commencant par so
quelqu´un peu m´aider SVP merci
PMO
Bonjour,
Une piste avec le code suivant
A) Créez un UserForm propriété (Name) = UserForm1 et y inclure un contrôle Intitulé propriété (Name) = Label1 un contrôle Zone de texte propriété (Name) = TextBox1 un contrôle Zone de liste propriété (Name) = ListBox1
B) Double cliquez sur le UserForm pour faire apparaître sa fenêtre de code, effacez le code existant et copiez y le code suivant
******************************** Const LIG_MAX As Long = 65536 Dim S2 As Worksheet Dim numCol& '__________________________________ Private Sub ListBox1_DblClick( _ ByVal Cancel As MSForms.ReturnBoolean) ActiveSheet.Range(Cells(Me.ListBox1.Value, numCol&), _ Cells(Me.ListBox1.Value, numCol&)).Select End Sub '__________________________________ Private Sub TextBox1_Change() Dim A$ Dim var Dim R As Range Dim i& Dim fin& Dim T&() A$ = Me.TextBox1.Value Application.ScreenUpdating = False S2.Visible = xlSheetVisible S2.Activate var = S2.Range(Cells(1, 3), Cells(LIG_MAX, 3)) Set R = S2.Range(Cells(1, 2), Cells(LIG_MAX, 2)) R = var fin& = S2.Range(Cells(LIG_MAX, 2), _ Cells(LIG_MAX, 2)).End(xlUp).Row ReDim T&(1 To fin&, 1 To 1) For i& = 1 To fin& T&(i&, 1) = i& Next i& S2.Range("a1:a" & fin& & "") = T& For i& = 1 To fin& If UCase(Left(var(i&, 1), Len(A$))) <> _ UCase(A$) Then var(i&, 1) = "" Next i& R = var Set R = S2.Range("a1:b" & fin& & "") R.Sort Key1:=[b1], Order1:=xlAscending, _ Key2:=[a1], Order2:=xlAscending Set R = S2.Range(Cells(1, 1), _ Cells(S2.Range(Cells(LIG_MAX, 2), _ Cells(LIG_MAX, 2)).End(xlUp).Row, 2)) Me.ListBox1.RowSource = R.Address S2.Visible = xlSheetVeryHidden Application.ScreenUpdating = True End Sub '__________________________________ Private Sub UserForm_Initialize() Dim var Dim S1 As Worksheet Dim R As Range Dim fin& Dim i& Dim T&() Me.ListBox1.ColumnCount = 2 Me.ListBox1.ColumnWidths = "0;20" If TypeName(Selection) <> "Range" Then Me.TextBox1.Visible = False Me.ListBox1.Visible = False Me.Label1 = "La sélection n'est pas une plage" Exit Sub End If Set S1 = ActiveSheet numCol& = S1.Range(Selection.Address).Column If S1.Range(Cells(LIG_MAX, numCol&), _ Cells(LIG_MAX, numCol&)).End(xlUp).Row = 1 And _ S1.Range(Cells(1, numCol&), _ Cells(1, numCol&)) = "" Then Me.TextBox1.Visible = False Me.ListBox1.Visible = False Me.Label1 = "La plage ne contient pas de données" Exit Sub End If var = S1.Range(Cells(1, numCol&), _ Cells(LIG_MAX, numCol&)) Application.ScreenUpdating = False Set S2 = ActiveWorkbook.Worksheets.Add Set R = S2.Range(Cells(1, 3), Cells(LIG_MAX, 3)) R = var Set R = S2.Range(Cells(1, 2), Cells(LIG_MAX, 2)) R = var fin& = S2.Range(Cells(LIG_MAX, 2), _ Cells(LIG_MAX, 2)).End(xlUp).Row ReDim T&(1 To fin&, 1 To 1) For i& = 1 To fin& T&(i&, 1) = i& Next i& S2.Range("a1:a" & fin& & "") = T& Set R = S2.Range("a1:b" & fin& & "") R.Sort Key1:=[b1], Order1:=xlAscending, _ Key2:=[a1], Order2:=xlAscending Set R = S2.Range(Cells(1, 1), _ Cells(S2.Range(Cells(LIG_MAX, 2), _ Cells(LIG_MAX, 2)).End(xlUp).Row, 2)) Me.ListBox1.RowSource = R.Address S2.Visible = xlSheetVeryHidden Application.ScreenUpdating = True End Sub '__________________________________ Private Sub UserForm_Terminate() Application.ScreenUpdating = False Application.DisplayAlerts = False If Not S2 Is Nothing Then S2.Visible = xlSheetVisible S2.Delete End If Application.DisplayAlerts = True Application.ScreenUpdating = True End Sub ********************************
C) Créez un module standard et copiez y le code suivant
******************************** Sub lancer() UserForm1.Show End Sub ********************************
D) Sélectionnez une cellule dont la colonne contient vos données à traiter et exécutez la macro "lancer" Le UserForm apparaît avec, dans la ListBox, vos données triées Dans la TextBox tapez une lettre et la ListBox sélectionne les données en fonction de cette lettre. Si vous tapez une 2ème lettre, bis repetita. Etc.
Bonne programmation
Cordialement
-- PMO Patrick Morange
Bonjour,
Une piste avec le code suivant
A) Créez un UserForm propriété (Name) = UserForm1 et y inclure
un contrôle Intitulé propriété (Name) = Label1
un contrôle Zone de texte propriété (Name) = TextBox1
un contrôle Zone de liste propriété (Name) = ListBox1
B) Double cliquez sur le UserForm pour faire apparaître sa
fenêtre de code, effacez le code existant et copiez y le code suivant
********************************
Const LIG_MAX As Long = 65536
Dim S2 As Worksheet
Dim numCol&
'__________________________________
Private Sub ListBox1_DblClick( _
ByVal Cancel As MSForms.ReturnBoolean)
ActiveSheet.Range(Cells(Me.ListBox1.Value, numCol&), _
Cells(Me.ListBox1.Value, numCol&)).Select
End Sub
'__________________________________
Private Sub TextBox1_Change()
Dim A$
Dim var
Dim R As Range
Dim i&
Dim fin&
Dim T&()
A$ = Me.TextBox1.Value
Application.ScreenUpdating = False
S2.Visible = xlSheetVisible
S2.Activate
var = S2.Range(Cells(1, 3), Cells(LIG_MAX, 3))
Set R = S2.Range(Cells(1, 2), Cells(LIG_MAX, 2))
R = var
fin& = S2.Range(Cells(LIG_MAX, 2), _
Cells(LIG_MAX, 2)).End(xlUp).Row
ReDim T&(1 To fin&, 1 To 1)
For i& = 1 To fin&
T&(i&, 1) = i&
Next i&
S2.Range("a1:a" & fin& & "") = T&
For i& = 1 To fin&
If UCase(Left(var(i&, 1), Len(A$))) <> _
UCase(A$) Then var(i&, 1) = ""
Next i&
R = var
Set R = S2.Range("a1:b" & fin& & "")
R.Sort Key1:=[b1], Order1:=xlAscending, _
Key2:=[a1], Order2:=xlAscending
Set R = S2.Range(Cells(1, 1), _
Cells(S2.Range(Cells(LIG_MAX, 2), _
Cells(LIG_MAX, 2)).End(xlUp).Row, 2))
Me.ListBox1.RowSource = R.Address
S2.Visible = xlSheetVeryHidden
Application.ScreenUpdating = True
End Sub
'__________________________________
Private Sub UserForm_Initialize()
Dim var
Dim S1 As Worksheet
Dim R As Range
Dim fin&
Dim i&
Dim T&()
Me.ListBox1.ColumnCount = 2
Me.ListBox1.ColumnWidths = "0;20"
If TypeName(Selection) <> "Range" Then
Me.TextBox1.Visible = False
Me.ListBox1.Visible = False
Me.Label1 = "La sélection n'est pas une plage"
Exit Sub
End If
Set S1 = ActiveSheet
numCol& = S1.Range(Selection.Address).Column
If S1.Range(Cells(LIG_MAX, numCol&), _
Cells(LIG_MAX, numCol&)).End(xlUp).Row = 1 And _
S1.Range(Cells(1, numCol&), _
Cells(1, numCol&)) = "" Then
Me.TextBox1.Visible = False
Me.ListBox1.Visible = False
Me.Label1 = "La plage ne contient pas de données"
Exit Sub
End If
var = S1.Range(Cells(1, numCol&), _
Cells(LIG_MAX, numCol&))
Application.ScreenUpdating = False
Set S2 = ActiveWorkbook.Worksheets.Add
Set R = S2.Range(Cells(1, 3), Cells(LIG_MAX, 3))
R = var
Set R = S2.Range(Cells(1, 2), Cells(LIG_MAX, 2))
R = var
fin& = S2.Range(Cells(LIG_MAX, 2), _
Cells(LIG_MAX, 2)).End(xlUp).Row
ReDim T&(1 To fin&, 1 To 1)
For i& = 1 To fin&
T&(i&, 1) = i&
Next i&
S2.Range("a1:a" & fin& & "") = T&
Set R = S2.Range("a1:b" & fin& & "")
R.Sort Key1:=[b1], Order1:=xlAscending, _
Key2:=[a1], Order2:=xlAscending
Set R = S2.Range(Cells(1, 1), _
Cells(S2.Range(Cells(LIG_MAX, 2), _
Cells(LIG_MAX, 2)).End(xlUp).Row, 2))
Me.ListBox1.RowSource = R.Address
S2.Visible = xlSheetVeryHidden
Application.ScreenUpdating = True
End Sub
'__________________________________
Private Sub UserForm_Terminate()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
If Not S2 Is Nothing Then
S2.Visible = xlSheetVisible
S2.Delete
End If
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
********************************
C) Créez un module standard et copiez y le code suivant
********************************
Sub lancer()
UserForm1.Show
End Sub
********************************
D) Sélectionnez une cellule dont la colonne contient vos données
à traiter et exécutez la macro "lancer"
Le UserForm apparaît avec, dans la ListBox, vos données triées
Dans la TextBox tapez une lettre et la ListBox sélectionne les données
en fonction de cette lettre. Si vous tapez une 2ème lettre, bis repetita. Etc.
A) Créez un UserForm propriété (Name) = UserForm1 et y inclure un contrôle Intitulé propriété (Name) = Label1 un contrôle Zone de texte propriété (Name) = TextBox1 un contrôle Zone de liste propriété (Name) = ListBox1
B) Double cliquez sur le UserForm pour faire apparaître sa fenêtre de code, effacez le code existant et copiez y le code suivant
******************************** Const LIG_MAX As Long = 65536 Dim S2 As Worksheet Dim numCol& '__________________________________ Private Sub ListBox1_DblClick( _ ByVal Cancel As MSForms.ReturnBoolean) ActiveSheet.Range(Cells(Me.ListBox1.Value, numCol&), _ Cells(Me.ListBox1.Value, numCol&)).Select End Sub '__________________________________ Private Sub TextBox1_Change() Dim A$ Dim var Dim R As Range Dim i& Dim fin& Dim T&() A$ = Me.TextBox1.Value Application.ScreenUpdating = False S2.Visible = xlSheetVisible S2.Activate var = S2.Range(Cells(1, 3), Cells(LIG_MAX, 3)) Set R = S2.Range(Cells(1, 2), Cells(LIG_MAX, 2)) R = var fin& = S2.Range(Cells(LIG_MAX, 2), _ Cells(LIG_MAX, 2)).End(xlUp).Row ReDim T&(1 To fin&, 1 To 1) For i& = 1 To fin& T&(i&, 1) = i& Next i& S2.Range("a1:a" & fin& & "") = T& For i& = 1 To fin& If UCase(Left(var(i&, 1), Len(A$))) <> _ UCase(A$) Then var(i&, 1) = "" Next i& R = var Set R = S2.Range("a1:b" & fin& & "") R.Sort Key1:=[b1], Order1:=xlAscending, _ Key2:=[a1], Order2:=xlAscending Set R = S2.Range(Cells(1, 1), _ Cells(S2.Range(Cells(LIG_MAX, 2), _ Cells(LIG_MAX, 2)).End(xlUp).Row, 2)) Me.ListBox1.RowSource = R.Address S2.Visible = xlSheetVeryHidden Application.ScreenUpdating = True End Sub '__________________________________ Private Sub UserForm_Initialize() Dim var Dim S1 As Worksheet Dim R As Range Dim fin& Dim i& Dim T&() Me.ListBox1.ColumnCount = 2 Me.ListBox1.ColumnWidths = "0;20" If TypeName(Selection) <> "Range" Then Me.TextBox1.Visible = False Me.ListBox1.Visible = False Me.Label1 = "La sélection n'est pas une plage" Exit Sub End If Set S1 = ActiveSheet numCol& = S1.Range(Selection.Address).Column If S1.Range(Cells(LIG_MAX, numCol&), _ Cells(LIG_MAX, numCol&)).End(xlUp).Row = 1 And _ S1.Range(Cells(1, numCol&), _ Cells(1, numCol&)) = "" Then Me.TextBox1.Visible = False Me.ListBox1.Visible = False Me.Label1 = "La plage ne contient pas de données" Exit Sub End If var = S1.Range(Cells(1, numCol&), _ Cells(LIG_MAX, numCol&)) Application.ScreenUpdating = False Set S2 = ActiveWorkbook.Worksheets.Add Set R = S2.Range(Cells(1, 3), Cells(LIG_MAX, 3)) R = var Set R = S2.Range(Cells(1, 2), Cells(LIG_MAX, 2)) R = var fin& = S2.Range(Cells(LIG_MAX, 2), _ Cells(LIG_MAX, 2)).End(xlUp).Row ReDim T&(1 To fin&, 1 To 1) For i& = 1 To fin& T&(i&, 1) = i& Next i& S2.Range("a1:a" & fin& & "") = T& Set R = S2.Range("a1:b" & fin& & "") R.Sort Key1:=[b1], Order1:=xlAscending, _ Key2:=[a1], Order2:=xlAscending Set R = S2.Range(Cells(1, 1), _ Cells(S2.Range(Cells(LIG_MAX, 2), _ Cells(LIG_MAX, 2)).End(xlUp).Row, 2)) Me.ListBox1.RowSource = R.Address S2.Visible = xlSheetVeryHidden Application.ScreenUpdating = True End Sub '__________________________________ Private Sub UserForm_Terminate() Application.ScreenUpdating = False Application.DisplayAlerts = False If Not S2 Is Nothing Then S2.Visible = xlSheetVisible S2.Delete End If Application.DisplayAlerts = True Application.ScreenUpdating = True End Sub ********************************
C) Créez un module standard et copiez y le code suivant
******************************** Sub lancer() UserForm1.Show End Sub ********************************
D) Sélectionnez une cellule dont la colonne contient vos données à traiter et exécutez la macro "lancer" Le UserForm apparaît avec, dans la ListBox, vos données triées Dans la TextBox tapez une lettre et la ListBox sélectionne les données en fonction de cette lettre. Si vous tapez une 2ème lettre, bis repetita. Etc.